C - separating name and surname using comma with strtok -


i have problem strtok. i'm trying separate first name last name using comma. when try using scanf , type "vincent,van gogh", returns vincent first name, last name returns van.

however, when use preset string, shows last name van gogh.

printf("enter name , surname: "); char name[100];// = "vincent,van gogh"; char firstname [100]; char lastname [100]; char* token;  scanf("%s", &name); token = strtok(name, ","); strcpy(firstname, token); token = strtok(null, ","); strcpy(lastname, token);  puts(firstname); puts(lastname); 

is there i'm missing in order make user input work?


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -