#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.. */ }
Output:
A file named material.txt will be creasted automatcially in the location where your .c file is present.
Here are the screenshots: