title: How do I allocate memory to my char pointer?
body: <p>My assignment is to allow the user to enter any input and print the occurrences of letters and words, we also have to print out how many one letter, two, three, etc.. letter words are in the string. I have gotten the letter part of my code to work and have revised my word function several times, but still can't get the word finding function to even begin to work. The compiler says the char pointer word is undeclared when it clearly is. Do I have to allocate memory to it and the array of characters?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  
  void findLetters(char *ptr);
  void findWords(char *point);
  
  
  int main()
  {
      char textStream[100]; //up to 98 characters and '\n\ and '\0'
  
      printf("enter some text\n");
      if (fgets(textStream, sizeof (textStream), stdin)) //input up to 99 characters
      {
          findLetters(textStream);
          findWords(textStream);
      }
      else
      {
          printf("fgets failed\n");
      }
  
      return 0;
  }
  
  void findLetters(char *ptr) //find occurences of all letters
  {
      int upLetters[26];
      int loLetters[26];
      int i;
      int index;
  
      for (i = 0; i &lt; 26; i++) // set array to all zero
      {
          upLetters[i] = 0;
          loLetters[i] = 0;
      }
      i = 0;
      while (ptr[i] != '\0') // loop until prt[i] is '\0'
      {
          if (ptr[i] &gt;= 'A' &amp;&amp; ptr[i] &lt;= 'Z') //stores occurrences of uppercase letters
          {
              index = ptr[i] - 'A';// subtract 'A' to get index 0-25
              upLetters[index]++;//add one
          }
  
          if (ptr[i] &gt;= 'a' &amp;&amp; ptr[i] &lt;= 'z') //stores occurrences of lowercase letters
          {
              index = ptr[i] - 'a';//subtract 'a' to get index 0-25
              loLetters[index]++;//add one
          }
          i++;//next character in ptr
      }
      printf("Number of Occurrences of Uppercase letters\n\n");
      for (i = 0; i &lt; 26; i++)//loop through 0 to 25
      {
          if (upLetters[i] &gt; 0)
          {
              printf("%c : \t%d\n", (char)(i + 'A'), upLetters[i]);
              // add 'A' to go from an index back to a character
          }
      }
      printf("\n");
      printf("Number of Occurrences of Lowercase letters\n\n");
      for (i = 0; i &lt; 26; i++)
      {
          if (loLetters[i] &gt; 0)
          {
              printf("%c : \t%d\n", (char)(i + 'a'), loLetters[i]);
              // add 'a' to go back from an index to a character
          }
      }
      printf("\n");
  }
  
  void findWords(char *point)
  {
      int i = 0;
      int k = 0;
      int count = 0;
      int j = 0;
      int space = 0;
      int c = 0;
      char *word[50];
      char word1[50][100];
      char* delim = "{ } . , ( ) ";
  
      for (i = 0; i&lt; sizeof(point); i++) //counts # of spaces between words
      {
          if ((point[i] == ' ') || (point[i] == ',') || (point[i] == '.'))
          {
              space++;
          }
      }
      char *words = strtok(point, delim);
      for(;k &lt;= space; k++)
      {
          word[k] = malloc((words+1) * sizeof(*words));
      }
  
          while (words != NULL)
          {
              printf("%s\n",words);
              strcpy(words, word[j++]);
              words = strtok(NULL, delim);
          }
  
      free(words);
  }
  </code></pre>