#include<stdio.h>
#include<conio.h>
int main()
{
FILE *p,*p2;
char c;
long l;
long x;
p=fopen("file1.txt","w");
printf("enter the content of file:");
while(c=getchar()!=EOF)
{
putc(c,p);
}
fclose(p);
p=fopen("file1.txt","r");
// l=fseek(p,1L,2);
l=ftell(p);
p2=fopen("file2.txt","r");
c=getc(p);
while(l!=-1)
{
if(c==' ')
{
x=ftell(p);
// fseek(p,-1L,1);
while(c=getc(p)!=' ')
{
putc(c,p2);
fseek(p,-2L,1);
}
// fseek(p,x+1,0);
}
fseek(p,x,0);
l=ftell(p);
c=getc(p);
}
fclose(p);
// fclose(p2);
p=fopen("file2.txt","r");
while(c=getc(p)!=EOF)
{
printf("%c",c);
}
fclose(p);
getch();
}
it is not writing anything to file2.txt. what is the problem? it is compiling correctly.it is writing to file1.txt but not to the file2.txt. why is it so ???
in this, i am reversing each word of the file1.txt and then writing it to the file2.txt. :'(