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
| #include <stdio.h>
#include <stdlib.h>
int main (int argc, char** argv)
{
FILE* file;
file = fopen("text.txt", "r");
if (file != NULL) {
int c, nb_numbers, nb_chars;
nb_numbers = 0;
nb_chars = 0;
c = fgetc(file);
while(c != EOF) {
if ((c >= '0') && (c <= '9')) {
nb_numbers = (nb_numbers + 1);
} else {
nb_chars = (nb_chars + 1);
}
c = fgetc(file);
}
fclose(file);
printf("main - Le nombre de caracteres est %d, le nombre de chiffres est %d\n", nb_chars, nb_numbers);
} else {
printf("main error - cannot open the file\n");
}
return EXIT_SUCCESS;
} |
Partager