Help

Discussion in 'C' started by thamiz, Aug 14, 2008.

  1. thamiz

    thamiz New Member

    Joined:
    Apr 16, 2008
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    i want to make a program in c :
    but am a bit stuck, so can you anyone jst guide me through it.
    Basically the program has to read in a whole paragraph, and the the program will have to find the words in the paragraph, then it has to sort the words into alphabetically order and and also count the number of times the word appeared in the paragraph and then print, the words in alphabetically order with the frequency.
    cheers , if anyone can just guide me through it it would be good. Ps i have developed the sorting algorithm for the program... its an insertion sort.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Try giving better titles for good responses.
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    How far have you got and where are you stuck? Do you know how to:
    - read words from a file?
    - store the words in a suitable data structure, updating the count if the word is already present?
    - sort the data into alphabetical order?
    If you're stuck on a specific part of the code, can you post a MINIMAL sample that shows the problem, explaining what exactly it isn't doing that you want it to (or is doing that you don't want it to)?
     
  4. faizulhaque

    faizulhaque New Member

    Joined:
    May 23, 2008
    Messages:
    210
    Likes Received:
    3
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Karachi
    Home Page:
    http://www.google.com
    @topic Creator:

    Admin is correct rather than making jst Help making effective title of furm, like Help In C programming or else.
     
  5. thamiz

    thamiz New Member

    Joined:
    Apr 16, 2008
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Here is my code for scanning my function,
    i need help on storing the word in an array; the program must find 1000 unique words.
    i have already implemented a sorting algorithm and am working on the frequency count rite now
    Code:
    #include<stdio.h>
    #include<ctype.h>
    #define MAXWORDS 20
    #define MAXLETTERS 20 
    int main(int argc,char *argv[]){
       int character=0;
       int flag=0;
       while(((character=getchar())!=EOF)){
          if (ispunct(character) && flag==0){
             printf("\n");
             flag=1;
          }
          if (isspace(character) && flag==0){
             printf("\n");
             flag=1;
          }
          if (isalpha(character)){
             putchar(character);
             flag=0;
          }
          
       }
       return 0;
    }
    
     
  6. faizulhaque

    faizulhaque New Member

    Joined:
    May 23, 2008
    Messages:
    210
    Likes Received:
    3
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Karachi
    Home Page:
    http://www.google.com
    @above
    do u want to jst store 1000 of charactor in a array, or what i found your code complex
     
  7. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    It would make sense to store the word and its count in an STL map ( http://en.wikipedia.org/wiki/Map_(C%2B%2B_container) ) using the word as the key and the count as the data.

    Then you don't need a counting algorithm as such; when you want to add a word to the list, first check it exists, if it does you increase the count; if not just add it with a count of 1. Also you don't need a sorting algorithm as map handles this for you.

    However if you're not allowed to use the STL then perhaps just store a struct of the string and its count in a static array (malloc), resizing it as necessary (realloc). Use insertion sort, i.e. just place a new word into its correct place and shift the remaining items up; this is likely to be quick enough on modern systems.
     
  8. thamiz

    thamiz New Member

    Joined:
    Apr 16, 2008
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    hi guys
    i made a scan function, but the compiler at uni doesn't like it, also gets only allows me to input multiple lines of code, which i need for my program, help anyone please!!!
    Code:
    printf("Enter the text:\n");
      gets(text);
      /* Extract the words from the text  */
      while(text[i] != '\0')
      {
        /* Skip over separators */
        while(is_separator(text[i]))
          ++i;
    
        /* It is either the end of the string or the start of a word    */
        /* As long as it is not the string terminator copy the character */
        len = 0;              /* Reset character count    */
        while((!is_separator(text[i])) && (text[i] != '\0'))
          buffer[len++] = text[i++];
        if(len>0)               /* Check we have some characters in the word */
        {
          buffer[len] = '\0';   /* We reached the end of a word so add terminator */
          addWord(buffer);      /* Add the word to the list */
        }
      }
    can any one please help me
     
  9. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Please be more specific. What compiler, and what platform? How exactly doesn't the compiler like it?
    What does "gets only allows me to input multiple lines of code" mean?
     
  10. Amit Kumar Saha

    Amit Kumar Saha New Member

    Joined:
    Aug 1, 2008
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    I am a new learner. can you help to just find out the frequency of numbers. given input will be in the range of 0 to 9.

    Thanking you in advance

    Amit
     
  11. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Please don't hijack other people's threads. If you have a new topic, start a new thread.
     
  12. Amit Kumar Saha

    Amit Kumar Saha New Member

    Joined:
    Aug 1, 2008
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    I don't know how I hijacked others thread ? I just faced a problem and a asked for your help.

    Is it hijacking? I thought you guys are helping others. But you are misunderstanding me.

    :disappoin

    :disappoin
     
  13. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    What he meant is don't jump into any thread with your question as that does not make it available to viewable to all unless someone visits the same thread where as new thread with your fresh query helps it because its visible to all the people.

    I hope you get what is the inner meaning of hijacking.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice