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();

}




SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment