2010-01-08 5 views
1

C.의 맞춤법 검사 프로그램을 도와주세요. 대다수의 코딩이 완료되었습니다 (제 생각에는 ...). 나는 왜 프로그램이 컴파일되지 않을지 확신 할 수 없어서 정말로 붙어있다. 틀림없이, 나는 여전히 아마추어 코더입니다. 코드에있는 나쁜 코딩 습관에 대해 몇 가지 제안을 해 주시겠습니까? 고맙습니다!사전 일치/맞춤법 검사 프로그램

오류 메시지 :

필요한 일 이죠
 
1>------ Build started: Project: project7, Configuration: Debug Win32 ------ 
1>Compiling... 
1>project7.c 
1>c:\users\x309\documents\visual studio 2008\projects\project7\project7\project7.c(16) : warning C4101: 'dictionaryWord' : unreferenced local variable 
1>c:\users\x309\documents\visual studio 2008\projects\project7\project7\project7.c(77) : warning C4029: declared formal parameter list different from definition 
1>c:\users\x309\documents\visual studio 2008\projects\project7\project7\project7.c(91) : warning C4013: 'strlen' undefined; assuming extern returning int 
1>c:\users\x309\documents\visual studio 2008\projects\project7\project7\project7.c(96) : warning C4013: 'strncmp' undefined; assuming extern returning int 
1>c:\users\x309\documents\visual studio 2008\projects\project7\project7\project7.c(101) : warning C4013: 'printf' undefined; assuming extern returning int 
1>c:\users\x309\documents\visual studio 2008\projects\project7\project7\project7.c(78) : warning C4101: 'i' : unreferenced local variable 
1>Linking... 
1>project7.obj : error LNK2019: unresolved external symbol _artLength referenced in function _spellCheck 
1>C:\Users\x309\Documents\Visual Studio 2008\Projects\project7\Debug\project7.exe : fatal error LNK1120: 1 unresolved externals 
1>Build log was saved at "file://c:\Users\x309\Documents\Visual Studio 2008\Projects\project7\project7\Debug\BuildLog.htm" 
1>project7 - 2 error(s), 6 warning(s) 

... 맞춤법 검사 루틴을 작성하는이 프로젝트에 하나의 단계가있다. spellCheck 함수에는 두 개의 매개 변수가 있습니다. 첫 번째 매개 변수 (article [])는 문자 배열에 대한 포인터입니다. 이 배열의 내용은 철자 검사가 필요한 기사입니다. 기사의 끝은 보통 0으로 표시됩니다 (문자열의 끝을 표시). 이 기사에는 구두점, 대소 문자, 숫자 및 약어가 포함됩니다. 귀하의 기능은 사전에서 찾을 수없는 기사의 모든 단어를 인쇄해야합니다. 사전은 함수에 대한 두 번째 매개 변수입니다 (자세한 내용은 나중에 설명).

#include <stdio.h> 
#include<string.h> 

char dictionary[1000000]; 
char article[100000]; 

void spellCheck(char[], char[]); 
int isLetter(char c); 
void removePunc(char article[]); 
void toLower(char article[]); 
void lowerDictionary(char dictionary[]); 
int artLength(char article[]); 
void nextArticleWord(char article[], char articleWord[], int artLength, char dictionary[]); 

int main(void) { 
    FILE* dict_file; 
    FILE* article_file; 
    int bytes_read; 
    char* p; 

    dict_file = fopen("american-english.txt", "r"); 
    if (dict_file == 0) { 
     printf("unable to open dictionary file \"american-english.txt\"\n"); 
     return -1; 
    } 

    article_file = fopen("article.txt", "r"); 
    if (article_file == 0) { 
     printf("unable to open file \"article.txt\"\n"); 
     return -1; 
    } 

    /* read dictionary */ 
    p = dictionary; 
    p = fgets(p, 100, dict_file); 
    while (p != 0) { 
     while (*p != '\0') { 
      p += 1; 
     } 
     p = fgets(p, 100, dict_file); 
    } 

    /* read article */ 
    p = article; 
    bytes_read = fread(p, 1, 1000, article_file); 
    p += bytes_read; 
    while (bytes_read != 0) { 
     bytes_read = fread(p, 1, 1000, article_file); 
     p += bytes_read; 
    } 
    *p = 0; 

    spellCheck(article, dictionary); 
} 



int articlePosition =0; 
int dictionaryPosition = 0; 




void spellCheck(char article[], char dictionary[]) { 
    char articleWord[50]; 
    char dictionaryWord[50]; 
    int articleLength = artLength(article); 
    removePunc(article); 
    toLower(article); 
    lowerDictionary(dictionary); 
    nextArticleWord(article, articleWord, articleLength, dictionary); 

} 

void nextDictionaryWord(char dictionary[], char dictionaryWord[]){ 
    int i; 
    for(i =0; dictionary[dictionaryPosition] != '\n'; i++){ 
     dictionaryWord[i] = dictionary[dictionaryPosition]; 
     dictionaryPosition++; 
    } 
} 
int isLetter(char c){ 
    if ((c>='a'&&c<='z') || (c>='A'&&c<='Z')) 
     return 1; 
    return 0; 
} 

void removePunc(char article[]){ 
    int i, j=0; 
    for (i =0; article[i] != 0; i++){ 
     if (isLetter(article[i])){ 
      article[j] = article[i]; 
      j++; 
     } 
     else if (!isLetter(article[i])){ 
      article[j] = ' '; 
      j++; 
     }  
    } 
} 

void toLower(char article[]){ 
    int i=0; 
    for(i; article[i] != 0; i++){ 
     if (article[i] >= 'A' && article[i] <='Z') 
      article[i] = article[i] + 32; 
    } 
} 

void lowerDictionary(char dictionary[]){ 
    int i=0; 
    for(i; dictionary[i] != 0; i++){ 
     if (dictionary[i] >= 'A' && dictionary[i] <= 'Z'){ 
      dictionary[i] = dictionary[i] + 32; 
     } 
    } 
} 


int articleLength(char article[]){ 
    int count=0; 
    while (article[count] != 0) 
     count++; 
    return count; 
} 

void nextArticleWord(char article[], char articleWord[], int articleLength, char dictionaryWord[], char dictionary[]){ 
    int j, i; 
check: 
    while(!isLetter(article[articlePosition])){ 
     if (article[articlePosition] == 0){ 
      return; 
     } 
     articlePosition++; 
    } 
    for(j=0; article[articlePosition] != ' ' || articlePosition == articleLength; j++){ 
     articleWord[j] = article[articlePosition]; 
     articlePosition++; 
    } 

    if (strlen(articleWord)<2){ 
     goto check; 
    } 
    articleWord[j+1] = 0; 
    //dictionary search 
     while (!strncmp(articleWord, dictionaryWord,strlen(articleWord))){ 
      nextDictionaryWord(dictionary, dictionaryWord); 
     } 
     if(strncmp(articleWord, dictionaryWord,strlen(articleWord))) 
      return; 
     printf(articleWord); 
} 

답변

1

당신은 앞으로 선언을 만든 :

int artLength(char article[]); 

을하지만 실제 구현은 다음과 같습니다

int articleLength(char article[]); 

것은 그들이 동일한 (둘 중 하나를 변경) 확인하고 프로젝트가 컴파일됩니다.

0

앞으로 나아갈 정보는 많지 않습니다. 앞으로는 실제 오류 메시지를 게시해야합니다. 그러나 함수 선언을 main() 함수보다 먼저 코드에 표시되도록 이동해야합니다.

0

컴파일러 오류를 경험하고 그 의미를 이해 했습니까?

커서가 눈에 띄기 때문에 여기에 문제가 있다고 생각합니다. 컴파일러 오류는 다음과 같습니다

오류 LNK2019 : 기본적으로 컴파일러를 의미되지 않은 외부 기호 _ 기능에서 참조 artLength _ 맞춤법 검사

함수에서 호출 artLength라는 기능을 찾고있다 맞춤법 검사. 그러나, 그것을 찾지 못했습니다.

articleLength이라는 기능이있는 것 같습니다. 작성한 것일 수도 있습니다.

그러나 컴파일러의 다른 모든 출력을 살펴보고 그 의미를 이해하도록 권할 것입니다. 컴파일러가 특정 함수를 찾지 못한다는 것은 기본적으로 많은 내용을 담고 있습니다. 실제로 함수를 작성하기 전에 호출하기 때문입니다.

0

댄의 대답은 절대적으로 좋지만 프로그램은 여전히 ​​컴파일되지 않습니다. spellCheck 함수에서 dictionaryWord [50]를 전달하지 않았으므로 Dan이 지적한 오류를 수정하자마자 컴파일러가 오류를 수정하자마자 "너무 적은 인수가 전달되었습니다"라는 오류가 표시됩니다.

이 질문을보고 C : D

의 맞춤법 검사기를 구현하려는 사용자를위한 것입니다.
관련 문제