Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Help (http://www.go4expert.com/forums/help-t12919/)

thamiz 14Aug2008 05:54

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 14Aug2008 09:15

Re: Help
Try giving better titles for good responses.

xpi0t0s 14Aug2008 13:20

Re: Help
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 14Aug2008 20:35

Re: Help
@topic Creator:

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

thamiz 15Aug2008 07:20

Re: Help
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

#define MAXWORDS 20
#define MAXLETTERS 20
int main(int argc,char *argv[]){
  int character=0;
  int flag=0;
      if (ispunct(character) && flag==0){
      if (isspace(character) && flag==0){
      if (isalpha(character)){
  return 0;

faizulhaque 15Aug2008 13:43

Re: Help
do u want to jst store 1000 of charactor in a array, or what i found your code complex

xpi0t0s 15Aug2008 14:40

Re: Help
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 18Aug2008 17:54

Re: Help
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!!!

printf("Enter the text:\n");
  /* Extract the words from the text  */
  while(text[i] != '\0')
    /* Skip over separators */

    /* 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 18Aug2008 18:56

Re: Help
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 19Aug2008 15:51

Re: Help
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


All times are GMT +5.5. The time now is 08:52.