Ôn thi olympic 2020
1. Đọc ghi file
1.1 Đọc file
int main() { int n; FILE *f = fopen("cow4.inp", "r"); // mo file de ghi if(f != NULL) { fscanf(f, "%d", &n); fclose(f); } else { printf("Loi doc file"); } return 0; }
1.2 Ghi file
#include <stdio.h> int main() { int n = 10; // khai bao bien ten FILE *f = fopen("output.txt", "w"); // mo file de ghi if(f != NULL) { fprintf(f, "%3d", n); fclose(f); // dong file fo } else { printf("Khong doc duoc file!"); } return 0; }