help me with this....here i m trying to write into a file(which i have already created n saved in C:\ drive) from stdinput i.e. keyboard and then reading from that file and displaying on stdoutput....but its isn't working... :rolleyes: :rolleyes:
tell me why?????????
by the way i m using GCC as compiler.......
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp ;
int offset ;
char ch ;
if ( ( fp = fopen ( "C:\q.txt", "w" )) == NULL )
{
printf ( "\nUnable to open file" ) ;
exit(0) ;
}
while((ch=getchar())!=EOF)
putc(ch,fp);
fclose ( fp ) ;
printf("\nData output\n\n");
if ( ( fp = fopen ( "C:\q.txt", "r" )) == NULL )
{
printf ( "\nUnable to open file" ) ;
exit(0) ;
}
while((ch=getc(fp))!=EOF)
printf ( "%c", ch ) ;
fclose ( fp ) ;
getch();
}
<< moderator edit: added [co[u][/u]de][/co[u][/u]de]
tags >>