#include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> void main() { clrscr(); FILE *fp; char s[100], fname[20]; printf("Enter the file name: "); gets(fname); fp=fopen(fname, "w"); if(fp==NULL) { printf("Cannot open file"); getch(); exit(1); } printf("\nEnter the input you want to write in the file :\n"); while(strlen(gets(s))>0) { fputs(s, fp); fputs("\n",fp); } fclose(fp); getch(); }
C program to write to file.
Reviewed by
on
December 26, 2019
Rating:
No comments: