Jump to content

Scanning a String Issue, recreating line of C code to Labview


Recommended Posts

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 by df_rob
Link to comment

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.

Link to comment

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.

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.