title: Segmentation Fault (core dump) error
body: <p>I am writing a program that is intended to count the number of times each word occurs in a text file. I am getting a runtime error that says: Segmentation fault (core dumped). I understand this has to do with trying to access memory that has not been allocated. </p>
  
  <p>Also, I am receiving warnings about my arguements for getline, and I am unsure if I am using it correctly. Any advice is appreciated. </p>
  
  <p>My code is:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define MAXWORDS 5000
  #define MAXLINE 1000
  #define MAXWORDLEN 100
  
  
  int count = 0;
  struct wordcount *wordPtr[MAXWORDS];
  
  typedef struct wordcount *wordcountptr;
  
  typedef struct wordcount {
      char word[50];
      int count;
  } wordcount_t;
  
  
  main()
  {
  
      int wordfound = 0;
      int len;
      char line[MAXLINE];
      int printcount;
  
      while ((len = getline(line, MAXLINE, stdin))&gt; 0)
      {
          int i = 0;
          int j = 0;
  
          for( ; i&lt;len; i++)
          {
              if(line[i] != isalnum(line[i]) &amp;&amp; line[i] != 32)
                  line[i] = 32;
              else
                  line[i] = tolower(line[i]);
          }
  
          for( ; j&lt;len; j++)
          {
  
              char currentword[MAXWORDLEN];
  
              if(line[j] != 32)
              {
                  for(i=0; line[j] != 32; i++)
                      currentword[i] = line[j];
              }
              if(line[j] == 32)
              {
                  for(i=0;i&lt;MAXWORDS; i++)
                  {
                      if(strcmp(currentword, (*wordPtr[i]).word) == 0)
                      {
                          (*wordPtr[i]).count++;
                          wordfound = 1;
                      }
                  }
  
                  if(wordfound == 0)
                  {
                      wordPtr[i] = (wordcount_t*)malloc(sizeof(wordcount_t));
                      strcpy((*wordPtr[i]).word, currentword);
                      (*wordPtr[i]).count = 1;
                      count++;
                  }
              }
              wordfound = 0;
          }
      }
  
      for(printcount = 0; printcount &lt; count; printcount++)
          printf("There are %d occurances of the word %s\n", (*wordPtr[printcount]).count, (*wordPtr[printcount]).word);
  
      for(printcount = 0; printcount &lt; MAXWORDS; printcount++)
      {
          free((void*)wordPtr[printcount]);
          wordPtr[printcount]= NULL;
      }
  }
  </code></pre>