Can someone please explaing why the string is not splitted in the following code
#include <stdio.h>
int main(void)
{
char name[] = "first:last";
char first[20], last[20];
sscanf(name, "%s:%s", first, last);
printf("first: %s, last: %s", first, last);
return 0;
}
The output is
first: first:last, last:
but it should be
first: first, last: last
Kindly check code here http://ideone.com/JDSTt
You can use something like this:
:is not whitespace, so a regular%swill not consider it as a delimiter. Seescanffor more details.(Edited demo: http://ideone.com/m4LVP)