title: Dictionary Matching / Spell Check Program
body: <p>Please help me with a spellcheck program in C. The majority of the coding are complete (I think...). I'm really stuck because I'm not sure why the program wouldn't compile. Admittedly, I'm still an amateur coder, would you also provide a few suggestions on some of the bad coding habits that I have in the code? Thank you!</p>
  
  <p>Error Message:</p>
  
  <pre>
  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)
  </pre>
  
  <p>What's required...
  There is only one stage on this project, writing the spellCheck routine. The spellCheck function has two parameters. The first parameter (article[]) is a pointer to an array of characters. The contents of this array are an article that you need to spell check. The end of the article is marked with the normal 0 (marking the end of a string). The article includes punctuation, upper and lower case words, numbers, and abbreviations. Your function must print every word in the article that cannot be found in the dictionary. The dictionary is the second parameter to the function (more on this later).</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include&lt;string.h&gt;
  
  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&gt;='a'&amp;&amp;c&lt;='z') || (c&gt;='A'&amp;&amp;c&lt;='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] &gt;= 'A' &amp;&amp; article[i] &lt;='Z')
              article[i] = article[i] + 32;
      }
  }
  
  void lowerDictionary( char dictionary[]){
      int i=0;
      for(i; dictionary[i] != 0; i++){
          if (dictionary[i] &gt;= 'A' &amp;&amp; dictionary[i] &lt;= '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)&lt;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);
  }
  </code></pre>