Write a program in C to append multiple lines at the end of a text file.

Previous
Next
#include<stdio.h>
int main()
{
	FILE *src, *dest;
	int ch;
	src = fopen("code.c", "r");
	dest = fopen("output.txt", "a");
	if(src != NULL)
	{
		while((ch = fgetc(src)) != EOF)
		{
			fputc(ch, dest);
		}
		printf("This program code is added to output.txt file in your systme\n");
		printf("If file is not present, it creates the new file \n");
		printf("If file is present, it appends the data\n");
		fclose(dest);
		fclose(src);
	}
	return 0;
}
Previous
Next

Courses Enquiry Form