#include <stdio.h>
#include <string.h>
int main(void)
{
    char str[41];
    printf("Input string: ");
    gets(str);
    str[41] = '\0';
    char* ptr = strtok(str, " ");
    while(ptr != NULL){
        printf("%s\n", ptr);
        ptr = strtok(NULL, " ");
    }
return 0;
}


strtok을 활용해 str(40글자 이하)을 단어별로 자르는 프로그램을 만들고 있습니다.

Input: 1 one 2 two 3 three 4 four ... (계속 진행)

output:

1

one

2

two

3

three

4

four

5

five

6

six

7a

프로그램 종료

이런식으로 진행됩니다.

여기서 7a의 a는 어디서 튀어나온 건가요?

혹시나 싶어 str의 마지막글자를 '\0'으로 수정해주어도 나옵니다

도움 부탁드립니다 ㅠ