944,092 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 783
  • C RSS
Nov 1st, 2009
0

need help with a simple C program

Expand Post »
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.
  1. char tempWord[50];
  2.  
  3. char hist[50][32];
  4.  
  5. while (fscanf(fp,"%s",tempWord)!= EOF || j<4){
  6.  
  7. if(doesWordExist(tempWord,hist[j]) == FALSE){
  8.  
  9. strcpy(hist[k],tempWord);
  10. hist[k][31] = 1;
  11. k++;
  12. }
  13.  
  14. else
  15.  
  16. hist[k][31]++;
  17. j++;
  18.  
  19. }
Last edited by hangman1060; Nov 1st, 2009 at 1:45 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hangman1060 is offline Offline
1 posts
since Nov 2009
Nov 2nd, 2009
-1
Re: need help with a simple C program
program for sin series
Reputation Points: 10
Solved Threads: 0
Newbie Poster
unathantsb is offline Offline
1 posts
since Nov 2009
Nov 3rd, 2009
-1
Re: need help with a simple C program
please give me a simple source code to change the font color of the text using c programming language
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tamilchelvi is offline Offline
2 posts
since Nov 2009
Nov 3rd, 2009
-1
Re: need help with a simple C program
give me a source code for changing color of the text using c
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tamilchelvi is offline Offline
2 posts
since Nov 2009
Nov 5th, 2009
0
Re: need help with a simple C program
  1. #include<stdio.h>
  2. main()
  3. {
  4. printf("Hello");
  5. }
Reputation Points: 4
Solved Threads: 2
Junior Poster in Training
imolorhe is offline Offline
51 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Help with self made atoi Function.
Next Thread in C Forum Timeline: Simple Problem give me solution





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC