Read in a file of words one word per line but can contain an

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

Solution

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

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

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

int main()
{
int n;
char line[50] = {\'\\0\'};
char reverseWord[50] = {\'\\0\'};
  
fr = fopen (\"dictionary.txt\", \"rt\");
while ( fgets ( line, sizeof line, fr ) != NULL )
{
//fputs ( line, stdout ); /* write the line */
int i = 0;
while(line[i] != \'\\0\'){
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;
}

 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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site