df_rob Posted April 23, 2013 Report Share Posted April 23, 2013 (edited) Hi, I’m looking to recreate this line of C code in a similar manner in LabVIEW. Any contributions are greatly appreciated, thanks. sscanf(aline, "%d%*1c%1c%1c%*1c%2c%*1c%f%f%d%f%f%*1c%5c%*1c%3c%*1c%5c%*1c%5c", &ic,c1,c2,comm,&axial,&radial,&angular,&efbhs, &holdinch,rext,amppercent,testcode,iac) below are three sample data strings that this function can read: 626 8.45 2.03 226 0.04 0.00 2 13.01 626 627 C 8.47 1.30 293 0.10 0.00 1.00 27 0 628 C 8.48 1.32 296 0.12 0.00 2.00 28 13.01 1 As you can see, in some cases some fields are missing (but still valid). In C this is straight forward to read but in labVIEW I can't seem to account for the cases where the data is not present. My current work around requires ignoring the errors the labVIEW 'scan string' function is throwing but there must be a valid way to do this in labVIEW! Usefull Info: - Fixed number of fields. - Data Not delimited. - Data generated from another program so I can't add delimiters. - The characters (%c) are being read as strings in my current labVIEW implementation. Edited April 23, 2013 by df_rob Quote Link to comment
shoneill Posted April 23, 2013 Report Share Posted April 23, 2013 What do you meant he data is nor delimited..... How do you separate adjacent floating point numbers with a scan formatter with "%f%f" in it? Limit the length of the strings being read by using %xs where "x" is the number of characters you want to read. The same goes for non-floating point numbers. %3d will read in a three-digit decimal number. Using this you should be able to get what you want. Quote Link to comment
mje Posted April 23, 2013 Report Share Posted April 23, 2013 One complicating factor is as far as I can tell you can't get LabVIEW to scan whitespace as a valid string using the %s notation. Hence using %5s to scan " 0.00" will work (note the leading space), but the pure whitespace string " " will not as the scan primitive seems to treat whitespace as insignificant. So you'll likely need to get more specific and use character classes, for example %5[a-zA-Z0-9. ] (also note the space character in the class). Someone please correct me if I'm wrong about this, but I've never figured another way while sticking to the scan primitive (I'm aware a regex can do the trick, but that's not the topic at hand). The other thing to wrap your head around is LabVIEW does not accept the %* syntax, so you'll need to replace your delimiters with valid constants. Your example strings all have spaces as delimiters, perhaps you can just use a "s"? Other than that, shoneil covered everything else I believe. 1 Quote Link to comment
df_rob Posted April 24, 2013 Author Report Share Posted April 24, 2013 Hey thanks for the feedback, that has resolved this issue! Quote Link to comment
Ton Plomp Posted April 24, 2013 Report Share Posted April 24, 2013 Don't forget to set the decimal seperator (%.; ) if you think your program will ever come to a decent part of the world. Ton Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.