📁⚡Beginner
Append Content of One Text File to Another
File append operation
Append to file using mode "a". This adds content to the end without overwriting.
Program Code
file_append.c
C
1#include <stdio.h>2#include <time.h>34int main() {5 FILE *file = fopen("log.txt", "a");6 7 if (file == NULL) {8 printf("Error opening file!\n");9 return 1;10 }11 12 // Get current time13 time_t now = time(NULL);14 char *timeStr = ctime(&now);15 16 // Append log entry17 fprintf(file, "Log entry at %s", timeStr);18 19 fclose(file);20 21 printf("Log entry added!\n");22 return 0;23}Output
Log entry added!
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials