linux c언어 coredumped 에러입니다 ㅠ 프로그래밍 괴수님들 부탁드립니다

rkdwlss2의 이미지

파일로 올렸습니다 ㅠㅠㅠ printf("%s")이부분에서 오류뜨는거 같은데 어떻게 에러가 안뜨게 할지 모르겠습니다.
초보라서 자세하게 알려주시면 감사하겠습니다. 부탁드립니다 ㅠ 수정했습니다. 만약에 a a i i ai ai 이렇게 3개가 같으면 오류뜨는것 같습니다.

#include <stdio.h>
#include <string.h>
 
typedef struct tokfq freq;
struct tokfq{
        char *token;
        int frequency;
};
void frequency(char *tokens[],freq fq[]){
        int i=0,j=0,n=0;
        while (tokens[i]!=NULL){
                for(j=0;j<n;j++){
                        if (strcmp(tokens[i],fq[j].token)==0){
                                fq[j].frequency++;
                                break;
                        }
                }
                if(j>=n){
                        fq[n].token=tokens[i];
                        fq[n].frequency=1;
                        n++;
                }
                i++;
        }
        printf("Frequencies: ");
        for (i=0;i<n;i++){
                printf("%s %d ", fq[i].token, fq[i].frequency);
        }
 
}
void tokenize(char buf[],char *tokens[]){
        tokens[0]=strtok(buf," ");
        int i=0, j;
        for(;;){
                i++;
                tokens[i]=strtok(NULL," ");
                if(tokens[i]==NULL)break;
        }
        printf("There were %d words:",i);
        for(j=0;j<i;j++){
                printf("%s ",tokens[j]);
        }
        printf("\n");
}
void max_fq(freq fq[]){
        int i=0, max_n=0;
        int fmax=fq[0].frequency;
        while (fq[i].frequency>0){
                if(fq[i].frequency>fmax){
                        fmax=fq[i].frequency;
                        max_n=i;
                }
                i++;
}
        printf("\nThe word with the max freq:%s\n",fq[max_n].token);
}
void read(char buf[]){
        printf("Enter a sentence\n");
        fgets(buf,50,stdin);
        buf[strlen(buf)-1]=0;
        printf("You entered %s\n",buf);
}
 
void main(){
        char buf[50];
        char *tokens[50];
        freq fq[30];
 
        read(buf);
        tokenize(buf,tokens);
        frequency(tokens,fq);
        max_fq(fq);
}
 
헉 죄송합니다 ㅠㅠ

File attachments: 
첨부파일 크기
Image icon error.jpg31.53 KB
Plain text icon code.txt1.89 KB
익명 사용자의 이미지

소스 코드는 본문에, <code> 태그로 감싸서.

정 안되면 *.c 내지 *.txt 파일로 올려야지요. 워드 파일에 넣어서 압축해서 올리는 건 상식 밖입니다.

보기 불편한 건 둘째치고 *.docx 같은 묵직한 파일 포맷은 신뢰할 수 있는 출처 아니면 안받아요.

익명 사용자의 이미지

                tokens[i]=strtok(NULL," ")+NULL;
                strlen(tokens[i]);
                if(tokens[i]==NULL)break;

이 부분이 이상하군요. 언젠가는 strtok이 NULL을 리턴할 것이라고 판단한 것은 좋습니다.
하지만 그 경우에 strlen는 NULL을 받게 되는데 어떻게 될까요?

rkdwlss2의 이미지

NULL부분과 strlen부분은 제가 잘못 넣어서 뺐습니다ㅠㅠㅠ
본문에서 다시 수정해서 넣었습니다ㅠㅠ감사합니다
그래도 안돌아가네요 ㅠ

익명 사용자의 이미지

(X) 안돌아가네요
(O) 이런저런 결과를 예상했었는데 (스크린샷)|(텍스트 로그)와 같이 다른 결과가 나오네요.

답변을 바란다면, 답변을 다는 데 쓸만한 정보를 제공해 줘야지요.
입만 떡 벌리고 있으면 누가 떠먹여줍니까