Thursday 8 June 2017

Text File Input Through C Language

Q : Write a C program to write a line of string in a text file.

Solution : 

#include<stdio.h>
void main()
{
     FILE *pt;
     char ch[100],c;
     int i;
     pt=fopen("test.txt","w");

     if(pt==NULL)
          puts("File Opening error");
     else
     {
          printf("Enter a line of text>> ");
          gets(ch);
          for(i=0;ch[i]!='\0';i++)
               fputc(ch[i],pt);
     }
     fclose(pt);
}

Download Source Code

No comments:

Post a Comment