Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
Thread: C: sscanf / extract substrings
10-27-2007, 10:25 PM #1
- Join Date
- Jan 2007
- Thanked 0 Times in 0 Posts
C: sscanf / extract substrings
There is a string named tmp which was saved using the format %s%c%s%c%s%c\n where
%s is a string without '\0' at the end of it and
%c is the '\0' character.
Is there any way to extract these three substrings using sscanf only one time?
I 've already tried
sscanf(tmp, "%s%s%s", entry->name, entry->surname, entry->address) but the result was nothing like the one I expected.
The solution I came up with is sth like
sscanf(tmp, "%s", entry.name);
sscanf(tmp + strlen(entry.name) + 1, "%s", entry.surname);
sscanf(tmp + strlen(entry.name) +
strlen(entry.surname) + 2,
which works fine.. But there must be a better way.. Any ideas?