Write a C Program to create file and write into it using file handling. Here’s simple Program to create file and write into it using file handling in C Programming Language.
Below is the source code for C Program to create file and write into it using file handling which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
/* C Program to create file and write into it using file handling */
#include<stdio.h>
int main()
{
FILE *fp;
char ch;
fp=fopen("C:\\Users\\acer\\Documents\\file4.txt","w");
printf("\nEnter the data to be stored in the file::\n");
while((ch=getchar())!=EOF)
putc(ch,fp);
fclose(fp);
// at run time
// press ctrl+d in linux
// ctrl+z in windows to for end of the file(EOF)
printf("\nData is successfully written to the file.!!!\n ");
return 0;
}
OUTPUT : :
/* C Program to create a file and write into it using file handling */
Enter the data to be stored in the file::
CodezClub
Programming
C Programs
Java Programs
File handling
^Z
Data is successfully written to the file.!!!
Process returned 0
Above is the source code for C Program to create file and write into it using file handling which is successfully compiled and run on Windows System.The Output of the program is shown above .
Below is the source code for C Program to create file and write into it using file handling which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
OUTPUT : :
Above is the source code for C Program to create file and write into it using file handling which is successfully compiled and run on Windows System.The Output of the program is shown above .
need an explanation for this answer? contact us directly to get an explanation for this answer