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.
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)?
@topic Creator: Admin is correct rather than making jst Help making effective title of furm, like Help In C programming or else.
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; }
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.
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
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?
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
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
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.