Read in a file of words one word per line but can contain an
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;
}
