たとえば「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→ ("
最後の「→(」を取り除くにはどうすればよいですか?