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 35 36
| #include <stdio.h>
#include <stdlib.h>
#define SIZEOF_TAB(tab) (int) (sizeof(tab)/sizeof(*(tab)))
int main(void)
{
int i;
int c;
FILE *fp = NULL;
int caracteres[] = {72, 73, 74, 75, 0, 97, 98, 99, 10};
/* On ouvre le fichier test.txt en écriture */
fp = fopen("test.txt", "w");
if (fp != NULL)
{
for (i = 0; i < SIZEOF_TAB(caracteres); ++i)
{
fprintf(fp, "%c", caracteres[i]);
}
fclose(fp), fp = NULL;
}
/* On ouvre le fichier test.txt en lecture */
fp = fopen("test.txt", "r");
if (fp != NULL)
{
while ((c = fgetc(fp)) != EOF)
{
printf("%d ", c);
}
fclose(fp);
}
return EXIT_SUCCESS;
} |
Partager