Bonjour,
J ai trouvé une fonction sur internet qui permet de lire une ligne dans un fichier.
Quelqu un pourrait il m aider a comprendre le code car je ne le comprend pas trop !
Merci de votre aide .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
31
32
33
34 # define MEM_SIZE 2048 char *get_next_line(const int fd) { char *str; static char buffer[MEM_SIZE]; static int i = 0; int j; static int k = 0; j = 0; str = malloc(MEM_SIZE * sizeof(char)); if (k == 0) k = read(fd, buffer, MEM_SIZE); if (i == k) return (NULL); while (i < k && buffer[i] != '\n') { str[j] = buffer[i]; i = i + 1; j = j + 1; } if (buffer[i] == '\n') i = i + 1; str[j] = '\0'; return (str); }
Partager