source file name: Readfile.C
#include<stdio.h>
int main()
{
int n;
char ch;
FILE *fp;
//clrscr();
fp=fopen("input.txt","w");
printf("\n enter information for file:\n ");
while((ch=fgetc(stdin))!=EOF)
{
fprintf(fp, "%c",ch);
}
fclose(fp);
printf("\n reads data from same file & display on screen :\n");
fp=fopen("input.txt","r");
while((ch=fgetc(fp))!=EOF)
{
printf( "%c",ch);
}
fclose(fp);
//getch();
return 0;
}
output:
0 Comments
Post a Comment