c - reading a string with spaces with sscanf -


For a project I am trying to read an int and string with a string. The only problem is that sscanf starts breaking a% s when a location is visible. Is there any way to get this limit anyway? Here's an example of what I'm trying to do:

  # include & lt; Stdio.h & gt; #to & lt include, stdlib.h & gt; Int main (int argc, char ** argv) {int age; Four * buffer; Buffer = mallok (200 * size (four)); Sscanf ("19 cool kids", "% d% s", and age, buffer); Printf ("% s is% d years old \ n", buffer, age); Return 0; }  

What is this print: "Cool is 19 years old" where I need a "cool baby is 19" Does anyone know the way to fix it?

The following line is a number (% (% [^ \ t \ n] ).

  sscanf ("19 cool baby",  "% D% [^ \ t \ n]", and age, buffer);  

Comments