Write a C Program to create file and write into it using file handling

Create file and write into it


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 .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

Leave a Reply