Algorithm
- fopen()
- fputs()
- fclose()
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main() {
FILE *file_ptr = fopen("append_file.txt", "a");
if (file_ptr == NULL) {
printf("File could not be opened!\n");
return 1; // Exit the program
}
// Data to append to the file
char data_to_append[] = "This data is appended to the file.\n";
// Append data to the file using fputs
fputs(data_to_append, file_ptr);
// Close the file
fclose(file_ptr);
printf("Data has been appended to the file successfully!\n");
return 0;
}
Copy The Code &
Try With Live Editor
Output
Data has been appended to the file successfully!
Demonstration
Appending in a File in C Programming, file writing in c, c file writing