Word frequency and sorting

This is a discussion on Word frequency and sorting within the C Programming forums, part of the General Programming Boards category; I've sent the source code ,Adak, for anyone else that wanted to help (which i really need) i could send ...

  1. #31
    Registered User
    Join Date
    Dec 2008
    Posts
    24
    I've sent the source code ,Adak, for anyone else that wanted to help (which i really need) i could send you my source code so far, but cannot display it in the board, sorry, i have a reason.

    O yeah what do you mean i must include it in the two word arrays i'll be using? and what is that compiler testing means? i must write a source code with that kind of argument?

    As i said, i got stuck in getting the specific words that was from the file to be printed in my program along with it's occurence

    By the way, i'm using Windows VIsta , so i don't have the Unix sorting function. I forgot to warn about it in the last part of my assignment, sorry.

  2. #32
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by zyxx_66 View Post
    I've sent the source code ,Adak, for anyone else that wanted to help (which i really need) i could send you my source code so far, but cannot display it in the board, sorry, i have a reason.

    O yeah what do you mean i must include it in the two word arrays i'll be using? and what is that compiler testing means? i must write a source code with that kind of argument?

    As i said, i got stuck in getting the specific words that was from the file to be printed in my program along with it's occurence

    By the way, i'm using Windows VIsta , so i don't have the Unix sorting function. I forgot to warn about it in the last part of my assignment, sorry.
    You can't use structures, according to the assignment. You'll need parallel arrays. One for words, and one for the tally of words.

    so add:

    Code:
    char words[1000][25] = { { '\0' } };
    int tally[1000] = { 0 };
    and for simplicity, we'll do this on the stack, so this goes before int main(), and after the #include lines of code.

    Then in your code, where you get a letter, you'll need to add that letter into a separate buffer. (we could use a special row of the same array, but let's not).

    Code:
    i = 0;
    while (!issspace(c) )  {
       buff[i++] = c; //where c is a char. Is your c a char?
    }
    
    /* Then we need to see if this word is in the words array */
    for(i = 0, inIt = 0; i < count; i++)  {  //assume it's not in the array
       if((strcmp(buff, words[i]) == 0)  {   //test each word
           inIt = 1;                         //it's in there, set the flag
           tally[i]++;                       //increment tally for that word
       }
    }
    if(inIt == 0)  {                         //it needs to be added to words
      strcpy(words[count], buff);            //copy the string into words at count's row
       tally[count]++;                       //increment tally[count] 
       count++;                              //increment count
    }
    I haven't run this code, so it may not be right, but it will be close. The string functions will need a header, of course, so add that, and see if this compiles and runs OK, so far, with the rest of your program.

    If you get stuck, you know where we are.
    Last edited by Adak; 12-16-2008 at 01:29 PM.

  3. #33
    Registered User
    Join Date
    Dec 2008
    Posts
    24
    Haha, i found this to be hard and frustating,
    any other method (easier) than this?

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help in sorting
    By franziss in forum C++ Programming
    Replies: 3
    Last Post: 09-18-2005, 01:00 AM
  2. Sorting a string
    By Roaring_Tiger in forum C Programming
    Replies: 12
    Last Post: 09-26-2004, 09:12 AM
  3. extra word printing
    By kashifk in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2003, 05:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21