c - sscanf using @ as delimeter -


using '@' sscanf as a delimeter, I can not find the expected result

< P> example:

  #include & lt; Stdio.h & gt; Int Main () {Four Buffs [512], Scan_book1 [512], Scan_book2 [512]; Sprintf (buf, "abc @ def"); Sscanf (buf, "% s @% s", scan_buf1, scan_buf2); Printf ("scan buffer 1 -% s scooter buffer 2 -% s \ n", scan_buff1, scan_buff2); Expected session: Scanned buffer1 - ABC scan buffer2 - def actual op: scanned buffer1 - ABC @ def scan buffer2 -  

I use some special syntax for "@" should do? I can not see anything for this in the man page.

After the

you can read, you will see that the "% s" format

The order of non-white characters

This means that until "% s" will read up to the letters It does not reach a white space. Since you do not have a white space in your input it will be read in the first string

You can solve this by using "% ["].

  sscanf (buf, "% [^ @] @% s", scan_buf1, scan_buf2);  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -