#include
void main()
{
FILE *fp;
char ch,fname[20];
clrscr();
printf("Enter the name of the file to be created:");
gets(fname);
fp=fopen(fname,"w");
printf("Now hit any key to store it in file.");
printf("(Press 'Esc' to break):\n");
do
{
printf("%c",(ch=getch()));
if(ch==' ')
ch='-';
if(ch=='\r')
printf("\n");
putc(ch,fp);
}while(ch!=27);
fclose(fp);
printf("\nData has been saved into file.Do you want to see it?(y/n):");
printf("%c",(ch=getch()));
if(ch=='Y'||ch=='y')
{
printf("\n");
fp=fopen(fname,"r");
while(!feof(fp))
{
ch=getc(fp);
if(ch=='-')
ch=' ';
printf("%c",ch);
}
}
else
printf("\nOk Thanks! The program will exit now.");
getch();
}
No comments:
Post a Comment