Question
My order is wrong in the code. the output is not in the right order it should be and it includes periods and exclamation points.
My order is wrong in the code. the output is not in the right order it should be and it includes periods and exclamation points. how do i fix this?
#include
int main()
{
char string[1000], words[50][1000], temp[1000];
int i=0, j=0, k=0, n=0, count;
//uses fgets to read input from the user with max 1000 printf("Enter your input string: "); fgets(string, 1000, stdin);
//adds null terminating character in end of string string[strlen(string) - 1] = '\0';
//while loop to put string into a parallel integer array while (string[i] != '\0')
{ if (string[i] == ' ' ||string[i] == ',' || string[i] == . || string[i] == !)
{ //adds null terminating character when end of word words[j][k] = '\0'; //sets k=0 and j keeps on adding k = 0; j++; }
else { words[j][k++] = string[i]; } i++; } // adds null terminating character when done in two dimensional words words[j][k] = '\0'; n = j;
//sorts the words into temp
for (i = 0; i
{ //copies words[i] into temp to swap them later strcpy(temp, words[i]); for (j = i + 1; j
{ // if words[i] and [j] are not equal they get swapped if (strcmp(words[i], words[j]) > 0)
{ strcpy(temp, words[j]); strcpy(words[j], words[i]); strcpy(words[i], temp); } } //inner for } //outer for
printf("Frequency of words: "); i = 0;
//finds the frequency of each word and put them into counter variable while (i
//count indicates frequency of word at words[i] // -9 in print f so it is spaced as the output in project PDF shows printf("%-9s\t%d ", words[i], count);
//goes to the next word i = i + count; }
printf(" "); return 0; }
the right output is under the "expected:" portion. thank you very much for the help
Enter your input string: Frequency of words: came conquered! saw Expected: Enter the sentnece: I came, I saw, I conquered Output came saW conquered Enter your input string: Frequency of words: know more read the things will you Expected the more you read the more things you will know Output the more 2 you read things will knowStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started