Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Read in a file of words (one word per line, but can contain any number of words.

ID: 3797677 • Letter: R

Question

Read in a file of words (one word per line, but can contain any number of words...Including zero words!) Reverse each word Sort the resulting list of reversed words Write the sorted list of reversed words to a file Other notes: No using system commands to do this for you, you must use C code. You must linking in my reverse code to reverse each word (reverse. h, reverse. c and reverse. o are provided for you in Moodle) Using a dynamic array for your word list will result in more points than counting lines and then creating a statically sized word list You may link in your own vector code if you so desire (but you are NOT required to) All words will be AT MOST 50 characters Input file will be named "dictionary.txt" and an example file is provided in Moodle for you to test with You need to make sure that you are: Correctly linking/using my reverse code Proper use of dynamic array(s) String sorting Input processing Output processsing

Explanation / Answer

#include <stdio.h>
#include <string.h>

FILE *fr;
char str[10][50];

void reverseword(char word[],char reverseWord[]){
int i = 0;
while(word[i] != ''){
i++;
}
int j = 0, k= 0;
printf("Reverse Word :");
for(j = i; j >= 0 ; j--){
printf("%c",word[j]);
reverseWord[k] = word[j];
k++;
}   
}

int main()
{
int n;
char line[50] = {''};
char reverseWord[50] = {''};
  
fr = fopen ("dictionary.txt", "rt");
while ( fgets ( line, sizeof line, fr ) != NULL )
{
//fputs ( line, stdout ); /* write the line */
int i = 0;
while(line[i] != ''){
i++;
}
int j = 0;
for(j = i; j >= 0; j--){
reverseWord[i-j] = line[j];
}
  
int k = 0;
for( k= 0 ; k <= i ; k++){
printf("%c",reverseWord[k]);
}
printf(" ");
}
fclose(fr); /* close the file prior to exiting the routine */
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote