| | |
need help with a simple C program
The programming assignment is to read a text file, extract the words from it, and save them in a 2D array that contains the word and the number of occurrences of that word. For example, if a text file contains the words "first" "second" "third" "second", the array should contain - first 1 second 2 third 1. The code I have posted creates a 2D array that contains first 1 second 1 third 1 second 1, so the count for second does not increment and word is printed again. I am saving each new word in the hist array and the number in the 31st element of the array. Then, if the word does exist I want to increment that number. doesWordExist is function that returns FALSE if the word does not exist and TRUE if the word exists. The function has been tested and works correctly. I am also initializing the arrays. Pointers aren't allowed.
Please help me with this! I have been working on this for a long time and would appreciate your help very much.
Please help me with this! I have been working on this for a long time and would appreciate your help very much.
Last edited by hangman1060; Nov 1st, 2009 at 1:45 pm.
char tempWord[50]; char hist[50][32]; while (fscanf(fp,"%s",tempWord)!= EOF || j<4){ if(doesWordExist(tempWord,hist[j]) == FALSE){ strcpy(hist[k],tempWord); hist[k][31] = 1; k++; } else hist[k][31]++; j++; }
0
•
•
•
•
please give me a simple source code to change the font color of the text using c programming language
Other Threads in the C Forum
- Previous Thread: Help with self made atoi Function.
- Next Thread: Simple Problem give me solution
| Thread Tools | Search this Thread |
Tag cloud for C
api array arrays binary binarysearch c++ calculate char codes coke command conversion convert cprogramme database decimal directory dude dynamic error evaluation exec fgets file fork function functions getlasterror givemetehcodez global grade graphics help.forensic homework i/o input insert int integer km lazy leak leet_speak line linked linkedlist linux list logical_drives loop malloc matrix memory messagebox motherboard multi mysql no-effort number opensource output path performance pointer pointers printf problem probleminc process program programming read recursion recursive recv reverse roman2decimal scanf segmentationfault socketprograming spoonfeeding sql stdout steganography string strings strtok structures student studio system systemcall turbo turbo-c unix user variable wab why-not-to-use-turbo windows



