Write Character to File

#include<stdio.h>
#include<conio.h>
void main()
{
          FILE *fp;
          char ch;
          clrscr();
          fp=fopen("temp.txt","w");
          if (fp==NULL)
            {
                   printf("\n Error");
                   exit(0);
            }
          // write character to file
          printf("\n\nEnter Characters : \n");
          while((ch=getchar())!=EOF)
            {
                   fputc(ch,fp);
            }
          printf("\n data written successfully in file");
          fclose(fp);
          getch();
}

Post a Comment

Previous Post Next Post