Entering data in file using file handling in C [Program]

#include <stdio.h>
main( )
     FILE *fp;
     char material[1000];

     fp = fopen("material.txt","w"); /* open for writing */
     printf("Enter the material to be written in the text file.\n");
     gets(material); /* For including spaces we use gets function here! */
     fprintf(fp,"%s", material);
     fclose(fp); /* close the file before ending program to ensure no errors in extreme case.. */




A file named material.txt will be creasted automatcially in the location where your .c file is present.

Here are the screenshots:

1.1 1.2 1.3

Leave a Reply

Your email address will not be published.