0
문자열을 사용하여 문자열을 단어로 분리하고 "word1 + word2 + word3 ..."과 같은 형식으로 분리 된 단어를 넣으려는 프로그램을 작성하려고합니다. C 프로그램은 문자열을 가져 와서 문자열을 단어로 분리합니다. 그러나 각 단어를 유지하고 위의 형식으로 배치하는 방법에 대해서는 약간 혼란 스럽습니다. 여기 분리 된 문자열 저장
내 코드 지금까지 이 가#include <stdio.h>
#include <string.h>
int main()
{
int wordCount = 0;
char realString[200];
char testString[200];
char * nextWordPtr;
printf("Input string\n");
gets(realString);
strcpy(testString,realString);
nextWordPtr = strtok(testString," "); // split using space as divider
while (nextWordPtr != NULL) {
printf("word%d %s\n",wordCount,nextWordPtr);
wordCount++;
nextWordPtr = strtok(NULL," ");
}
}
가
사람이 어떤 제안이 있습니까입니까?
while (input_string [index]! = EOF)'는 잘못된 조언처럼 보입니다. 어쩌면 당신은 '\ 0'에 대해서 테스트 할 생각이었을까요? – wildplasser
@wildplasser : 오타입니다. – TOC