This is supposed to reverse every word in a file. From the command line output looks like its stuck somewhere.
Code:
/*Reverse every word in a file*/
#include<stdio.h>
int main()
{
FILE *fin,*fout;
int i=0, flag=0;
char temp[20],ch;
fin=fopen("/home/abhishek/Desktop/lol.txt","r");
if(fin==NULL)
{
printf("\nError opening input file\n");
return 1;
}
fout=fopen("/home/abhishek/Desktop/rofl.txt","w");
if(fout==NULL)
{
printf("\nError opening output file\n");
return 2;
}
ch=fgetc(fin);
if(ch==EOF)
flag=1;
while(ch!=EOF && flag==0 )
{
i=0;
while(ch!=EOF && ch!=' ' && ch!='\t' && ch!='.')
{
temp[i]=ch;
printf("\nreading....%d",i);
i++;
ch=fgetc(fin);
if(ch==EOF)
flag=1;
}
i--;
while(i>=0)
{
printf("\nwriting....%d",i);
fputc(temp[i],fout);
i--;
}
}
printf("\nDone!\n");
fclose(fin);
fclose(fout);
return 0;
}
CLI output
abhishek@dreamcatcher:~/Projects/C$ ./reverse
reading....0
reading....1
reading....2
reading....3
reading....4
reading....5
reading....6
writing....6
writing....5
writing....4
writing....3
writing....2
writing....1
| <-------cursor keeps waiting here for don't know what
Thanks for the help