Header Ad

C Program to perform file operations

In this tutorial, we are going to write a C Program to perform file operations in C Programming with practical program code and step-by-step full complete explanation.

C Program to perform file operations


C Program to perform file operations.

 
#include<stdio.h>
#include<conio.h>

void main()
{
	file *fp,*fp1;
	char c;

	clrscr();

	fp=fopen("test.c",'w');

	printf("\nEnter the content for file1(#.end)\n");

	c=getchar();

	while(c!='#')
	{
		fputc(c,fp);
		c=getchar();
	}

	rewind(fp);
	fp=fopen("test.c","r");

	fp1=fopen("tes.c","w");

	c=fgetc(fp);

	while(c!=eof)
	{
		fputc(c,fp);
		c=fgetc(fp);
	}

	fclose(fp);
	fclose(fp1);

	fp1=fopen("tes.c","r");
	c=fgetc(fp1);

	printf("\nThe contents in file 2\n");

	while(c!=eof)
	{
		putchar(c);
		c=fgetc(fp1);
	}
	fclose(fp1);

	getch();
}


Output

 
Enter the contents of file1(#-end)
good morning#
the contents of file2
good morning


Post a Comment

0 Comments