Help

thamiz's Avatar, Join Date: Apr 2008
Go4Expert Member
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.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Try giving better titles for good responses.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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)?
faizulhaque's Avatar, Join Date: May 2008
Skilled contributor
@topic Creator:

Admin is correct rather than making jst Help making effective title of furm, like Help In C programming or else.
thamiz's Avatar, Join Date: Apr 2008
Go4Expert Member
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;
}
faizulhaque's Avatar, Join Date: May 2008
Skilled contributor
@above
do u want to jst store 1000 of charactor in a array, or what i found your code complex
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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.
thamiz's Avatar, Join Date: Apr 2008
Go4Expert Member
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
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
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?
Amit Kumar Saha's Avatar, Join Date: Aug 2008
Go4Expert Member
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