
II-308 Programming Concepts
fp=fopen(“data.txt”,”w+”);
if(fp==NULL)
{
printf("Can not open file");
exit(1);
}
printf("Write data & to stop press '.' :");
while(c!='.')
{
c=getche();
fputc(c,fp);
}
rewind(fp);
printf("\n Contents read :");
while(!feof(fp))
printf("%c",getc(fp));
}
OUTPUT:
Write data and to stop press '.': ABCDEFGHIJK.
Contents read : ABCDEFGHIJK.
3.
#include <stdio.h>
#include <conio.h>
#include <process.h>
void main()
{
FILE *fp;
char c=' ';
clrscr();
fp=fopen("data.txt","a+");
if(fp==NULL)
{
printf("Can not open file");
exit(1);
}
printf("Write data & to stop press '.' :");
while(c!='.')
{
c=getche();
fputc(c,fp);
}
M14_ITL-ESL4791_02_SE_C14.indd 308 12/22/2012 5:06:43 ...