Consider the following code for tokenizing the string at space characters,
int main()
{
char L[100];
fgets(L, 100, stdin);
for(char* token = strtok(L, " "); token != NULL; token = strtok(NULL, " ")){
char L1[10];
strcpy(L1, token);
printf("%s", L1);
}
}
When the input is given as,
60@2 120@3
It eventually prints out as expected,
60@2120@3
Now, I would like to tokenize the string again that contains "@" character, Say, I wanna tokenize 60@2 and 120@3 with "@" character.
So, I started with the following code,
int main()
{
char L[100];
fgets(L, 100, stdin);
for(char* token = strtok(L, " "); token != NULL; token = strtok(NULL, " ")){
char L1[10];
strcpy(L1, token);
printf("%s", L1);
char* token2 = strtok(L1, "@"); // extra line 1
printf("%s", token2); // extra line 2
}
}
However for the same input,
60@2 120@3
The output generated was,
60@26022
Can you explain what is happening in the second case?