I'm trying to find a way to split a single string into two separate variables. Right now I have:
char buffer[1024];
char firstName[16];
char lastName[16];
fgets(buffer, 1024, stdin);
sscanf(buffer, "%s %s", firstName, lastName);
When I later print the data, the first name is fine, but the last name will be the first and last combined. For example, when I enter "Joe Bob", the first would print "Joe" and the second would print out "Joe Bob". I have tried a few other ways such as using strtok and even sscanf with an offset pointer, but I keep getting the same result. How would I go about having the last name only contain the second name? I am using ansi C. Any help would be greatly appreciated.