File I/O (Input/Output)
File I/O (Input/Output) in C. This allows you to read from and write to files, which is essential for many applications.
File I/O in C
FILE *fopen(const char *filename, const char *mode);int fclose(FILE *stream);#include <stdio.h>
int main() {
FILE *file = fopen("example.txt", "w"); // Open file for writing
if (file == NULL) {
printf("Error opening file\n");
return 1;
}
// Write to the file
fprintf(file, "Hello, World!\n");
// Close the file
fclose(file);
return 0;
}Reading from Files
Writing to Files
Error Handling
Summary
Last updated