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 37 38 39 40 41 42 43 44 45 46
|
#include <stdlib.h>
#include <stdio.h>
#define SIZE 4
int main()
{
int j, cpt, number1, number2;
int obs;
int tab[4];
int smax = sizeof tab/ sizeof * tab;
char filename[3];
FILE *file;
for(j = 0; j <= SIZE; j++)
{
sprintf(filename,"/tmp/J%d",j);
if ((file = fopen ( filename, "r" )) == NULL)
{
perror ("Impossible d'ouvrir le fichier.");
}
else
{
while ( fscanf ( file, "%d %d", &number1, &number2 ) == 2)
tab[j] = number2;
printf("tab[%d] = %d\n", j, tab[j]);
fclose (file);
}
}
printf("Numéro à compter ? ");
scanf("%d",&cpt);
/* compteur */
obs = 0;
for(j = 0; j <= smax; j++)
{
printf("tab[%d] = %d\n", j, tab[j]);
if(tab[j] == cpt)
{
obs = obs + 1;
}
}
printf("Total : %d\n", obs);
return EXIT_SUCCESS;
} |
Partager