View Full Version : C: sscanf / extract substrings

10-27-2007, 11:25 PM
Hello everyone..

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,
"%s", entry.address);

which works fine.. But there must be a better way.. Any ideas?