我编写了一个程序,我想输入例如“11:12”,然后返回“11”和“12”。这是我的代码:
#include<stdio.h>
#include <string.h>
#include <conio.h>
int main(void)
{
char s[] = "";
char seperator[] = ":";
char *ch;
while (1)
{
scanf("%s", &s); //scanf("%s", &s);
if (s == -1) break;
char *result = NULL;
result = strtok(s, seperator);
while( result != NULL ) {
printf( "result is \"%s\"\n", result );
result = strtok( NULL, seperator );
}
fflush(stdout);
}
return 0;
}
但是当我输入“11:12”时,这是我的输出:
result is "11"
result is "12→ ("
我怎样才能摆脱最后一个“→(”?