Count the number of occurrences of each word <p>I'm trying to count the number of occurrences of each word in the function <code>countWords</code> I believe i started the for loop in the function properly but how do I compare the words in the arrays together and count them and then delete the duplicates? Isn't it like a fibonacci series or am I mistaken? Also <code>int n</code> has the value of 756 because thats how many words are in the array and <code>wordsArray</code> are the elements in the array. </p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; #include &lt;ctype.h&gt; int *countWords( char **words, int n); int main(int argc, char *argv[]) { char buffer[100]; //Maximum word size is 100 letters FILE *textFile; int numWords=0; int nextWord; int i, j, len, lastChar; char *wordPtr; char **wordArray; int *countArray; int *alphaCountArray; char **alphaWordArray; int *freqCountArray; char **freqWordArray; int choice=0; //Check to see if command line argument (file name) //was properly supplied. If not, terminate program if(argc == 1) { printf ("Must supply a file name as command line argument\n"); return (0); } //Open the input file. Terminate program if open fails textFile=fopen(argv[1], "r"); if(textFile == NULL) { printf("Error opening file. Program terminated.\n"); return (0); } //Read file to count the number of words fscanf(textFile, "%s", buffer); while(!feof(textFile)) { numWords++; fscanf(textFile, "%s", buffer); } printf("The total number of words is: %d\n", numWords); //Create array to hold pointers to words wordArray = (char **) malloc(numWords*sizeof(char *)); if (wordArray == NULL) { printf("malloc of word Array failed. Terminating program.\n"); return (0); } //Rewind file pointer and read file again to create //wordArray rewind(textFile); for(nextWord=0; nextWord &lt; numWords; nextWord++) { //read next word from file into buffer. fscanf(textFile, "%s", buffer); //Remove any punctuation at beginning of word i=0; while(!isalpha(buffer[i])) { i++; } if(i&gt;0) { len = strlen(buffer); for(j=i; j&lt;=len; j++) { buffer[j-i] = buffer[j]; } } //Remove any punctuation at end of word len = strlen(buffer); lastChar = len -1; while(!isalpha(buffer[lastChar])) { lastChar--; } buffer[lastChar+1] = '\0'; //make sure all characters are lower case for(i=0; i &lt; strlen(buffer); i++) { buffer[i] = tolower(buffer[i]); } //Now add the word to the wordArray. //Need to malloc an array of chars to hold the word. //Then copy the word from buffer into this array. //Place pointer to array holding the word into next //position of wordArray wordPtr = (char *) malloc((strlen(buffer)+1)*sizeof(char)); if(wordPtr == NULL) { printf("malloc failure. Terminating program\n"); return (0); } strcpy(wordPtr, buffer); wordArray[nextWord] = wordPtr; } //Call countWords() to create countArray and replace //duplicate words in wordArray with NULL countArray = countWords(wordArray, numWords); if(countArray == NULL) { printf("countWords() function returned NULL; Terminating program\n"); return (0); } //Now call compress to remove NULL entries from wordArray compress(&amp;wordArray, &amp;countArray, &amp;numWords); if(wordArray == NULL) { printf("compress() function failed; Terminating program.\n"); return(0); } printf("Number of words in wordArray after eliminating duplicates and compressing is: %d\n", numWords); //Create copy of compressed countArray and wordArray and then sort them alphabetically alphaCountArray = copyCountArray(countArray, numWords); freqCountArray = copyCountArray(alphaCountArray, numWords); int *countWords( char **wordArray, int n) { return NULL; int i=0; int n=0; for(i=0;i&lt;n;i++) { for(n=0;n&lt;wordArray[i];n++) { } } } </code></pre>