VaultBy ENSAMIENParrainage
C30 lines

fichier-ecriture-lecture.c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
 * Écrire une ligne dans un fichier texte puis la relire.
 */

#include <stdio.h>

int main() {
    FILE *f = fopen("test.txt", "w");
    if (f == NULL) {
        printf("Erreur d'ouverture.\n");
        return 1;
    }

    fprintf(f, "Bonjour ENSAM\n");
    fclose(f);

    // Lecture
    char ligne[100];
    f = fopen("test.txt", "r");
    if (f == NULL) {
        printf("Erreur d'ouverture.\n");
        return 1;
    }

    fgets(ligne, sizeof(ligne), f);
    printf("Contenu lu : %s", ligne);
    fclose(f);

    return 0;
}

    Type at least 2 letters. ↑ ↓ to move, Enter to open.