Enter a line of text character by character and store in file and display the content !
#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
char ch ;
FILE *p,*p2;
// storing user input text to text file
p=fopen("demo.txt","w");
printf("enter the text you want to write in file till pressing enter\n ");
while((ch=getchar())!='\n')
{
fputc(ch,p);
}
fclose(p);
// reading the stored data from file demo.txt to user screen
p=fopen("demo.txt","r");
printf("stored text is :");
while(!feof(p))
{
ch = fgetc(p);
printf("%c",ch);
}
fclose(p);
getch();
}
0 comments:
Post a Comment