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) 이런저런 결과를 예상했었는데 (스크린샷)|(텍스트 로그)와 같이 다른 결과가 나오네요.

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

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.