- #include <stdio.h>
- #include <stdlib.h>
-
- ///////////// LE NOMBRE DE CARACTERES ////////////////
-
- int file_exists(char *filename);
-
- main()
- {
- char ch, source[80];
- int index;
- long count[127];
- FILE *fp;
-
- fprintf(stderr, "\nEntrez le nom du fichier source : ");
- gets(source);
-
- if(!file_exists(source))
- {
- fprintf(stderr, "\n%s n'existe pas.\n\n", source);
- exit(1);
- }
- else
- {
-
- if ((fp = fopen(source, "r")) == NULL)
- {
- fprintf(stderr, "\nErreur d'ouverture de %s en mode r.\n\n", source);
- exit(1);
- }
-
- for (index = 31; index<127; index++)
- {
- count[index] = 0;
- }
-
- while(1)
- {
- ch = fgetc(fp);
- if(feof(fp))
- {
- break;
- }
-
- if(ch > 31 && ch < 127)
- count[ch]++;
- }
-
- printf("\nChar\t\tCount\n");
- for (index=32; index<127; index++)
- printf("[%c]\t\t%d\n", index, count[index]);
-
- fclose(fp);
- return(0);
- }
- }
-
- int file_exists(char *filename)
- {
- FILE *fp;
- if((fp = fopen(filename, "r")) == NULL)
- {
- return 0;
- }
- else
- {
- fclose(fp);
- return 1;
- }
- }
#include <stdio.h>
#include <stdlib.h>
///////////// LE NOMBRE DE CARACTERES ////////////////
int file_exists(char *filename);
main()
{
char ch, source[80];
int index;
long count[127];
FILE *fp;
fprintf(stderr, "\nEntrez le nom du fichier source : ");
gets(source);
if(!file_exists(source))
{
fprintf(stderr, "\n%s n'existe pas.\n\n", source);
exit(1);
}
else
{
if ((fp = fopen(source, "r")) == NULL)
{
fprintf(stderr, "\nErreur d'ouverture de %s en mode r.\n\n", source);
exit(1);
}
for (index = 31; index<127; index++)
{
count[index] = 0;
}
while(1)
{
ch = fgetc(fp);
if(feof(fp))
{
break;
}
if(ch > 31 && ch < 127)
count[ch]++;
}
printf("\nChar\t\tCount\n");
for (index=32; index<127; index++)
printf("[%c]\t\t%d\n", index, count[index]);
fclose(fp);
return(0);
}
}
int file_exists(char *filename)
{
FILE *fp;
if((fp = fopen(filename, "r")) == NULL)
{
return 0;
}
else
{
fclose(fp);
return 1;
}
}