I'm parsing a string into variables and I almost have what I want.
The string to be parsed looks like this
char [128] = "D4 E 3 NullByte Sub";
Now I would like to split this into 4 variables:
- D4 would be the location
- E would be the direction
- 3 would be the length
- NullByte Sub is the name.
So far I've been using sscanf
for splitting into variables using the code below (assume that the variables are already created):
sscanf(line, "%s %s %d %s", location, direction, &length, name);
So this scans location, direction and length correctly but chops off the Sub
part of name.
I want to know how to ignore any other spaces and read what ever is left into name. No matter the number of spaces etc.
So if
line = "D4 E 3 NullByte Sub Ship Barrier"
Then I could expect the name to be
"NullByte Sub Ship Barrier"