C Program To Append Data Into A File

C Program To Append Data Into A File. If you are looking for append data into text file program in C, here in this tutorial we will help you to learn how to write a C program to append data into a text file.

C Program To Append Data Into A File

Learn how to write a C program to append data into a file. Writing appending data program in C can be done using various techniques but here in this program, we show how to write a c program to append data into a file in a proper way. Happy coding.

C Program to Append Data Into a File Source Code

Just copy paste the below source code to append data into a text file in C compiler to test, how the source code works. Happy Learning.

/* C Program to Append Data into a File - AppendFile.C */

#include <stdio.h>
#include <stdlib.h>
 
int main()
{
 FILE *fsring1, *fsring2, *ftemp;
 char ch, file1[20], file2[20], file3[20];
 
 printf("Enter name of first file ");
 gets(file1);

 printf("Enter name of second file ");
 gets(file2);

 printf("Enter name to store merged file ");
 gets(file3);

 fsring1 = fopen(file1, "r");
 fsring2 = fopen(file2, "r");

 if (fsring1 == NULL || fsring2 == NULL)
 {
   perror("Error has occured");
   printf("Press any key to exit...\n");
   exit(EXIT_FAILURE);
 }
 
 ftemp = fopen(file3, "w");
 if (ftemp == NULL)
 {
   perror("Error has occures");
   printf("Press any key to exit...\n");
   exit(EXIT_FAILURE);
 }
 while ((ch = fgetc(fsring1)) != EOF)
 fputc(ch, ftemp);

 while ((ch = fgetc(fsring2) ) != EOF)
 fputc(ch, ftemp);

 printf("Two files merged %s successfully.\n", file3);
 fclose(fsring1);
 fclose(fsring2);
 fclose(ftemp);
 return 0;
}

C PROGRAMMING EXAMPLES

  1. C Program to Accept Only Integer Values
  2. C Program To Arrange Numbers In Descending Order
  3. C Program to Add Days to Date
  4. C Program to Add Two Fractions
  5. C Program To Reverse A Number
  6. C Program to Find Maximum and Minimum Numbers
  7. C Program to Read a Text File
  8. C Program to Convert Decimal to Hexadecimal
  9. C Program to Convert Decimal to Binary
  10. C Program to Convert Celsius to Fahrenheit
  11. C Program To Find Absolute Value
  12. Ternary Operator Program in C
  13. C Program For Addition Table Using For Loop
  14. Denomination Program in C
  15. C Program to Print Multiplication Table 
  16. C Program Array with Example
  17. Binary Search in C Program Using Recursion
  18. Bubble Sort in C Using Pointers
  19. Bubble Sort Program in C Using Recursion
  20. Bubble Sort Program in C Using Array

Leave a Comment