Scusa la mia ignoranza!!!
Cmq questo è tutto ciò che ho fatto...
codice:
#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
int main()
{
int i, temp;
float distanza, frequenza[256];
char file1[]="italiano.txt";
char file2[]="latino.txt";
char file3[]="francese.txt";
char file4[]="tedesco.txt";
long totale;
unsigned char c;
FILE*fp1;
FILE*fp2;
FILE*fp3;
FILE*fp4;
FILE*fp5;
for (i=0; i<256; i++)
{
frequenza[i] = 0 ;
}
totale=0;
fp1=fopen(file1, "r");
if (fp1==NULL)
{
printf("Non trovo il file %s\n", file1);
getchar();
exit(-1);
}
fp2=fopen(file2, "r");
if (fp2==NULL)
{
printf("Non trovo il file %s\n", file2);
getchar();
exit(-1);
}
fp3=fopen(file3, "r");
if (fp3==NULL)
{
printf("Non trovo il file %s\n", file3);
getchar();
exit(-1);
}
fp4=fopen(file4, "r");
if (fp4==NULL)
{
printf("Non trovo il file %s\n", file4);
getchar();
exit(-1);
}
fp5=fopen("fileFrequenze.txt", "w");
if(fp5==NULL)
{
printf("Non trovo il file.\n");
getchar();
exit(-1);
}
/////////////////////////////////
// controllo delle frequenze
while ( fscanf(fp1, "%c", &c)== 1 )
{
/*
if(((c >'a') || (c < 'z'))||((c >'A') || (c < 'Z'))) // e'nella tabella ASCII ?
{
printf("%c", c);
}*/ //NON GUARDARE QUESTO ERA SOLO UNA PROVA CHE
//AVEVO IN MENTE DI FARE
temp = (int) c; // un cast fa solo bene per leggere un carattere
frequenza[temp]= frequenza[temp]+1;
totale = totale + 1 ;
}
for (i=0; i<256; i++) // normalizzazione dei conteggi
{
frequenza[i] = frequenza[i] / totale * 100 ;
}
/////////////////////////
// stampa delle frequenze ottenute sullo schermo
for (i=0; i<256; i++)
{
printf( "n=%d, \t %c, \t freq= %.8f\n", i , i, frequenza[i] );
}
fclose (fp1);
fclose (fp2);
fclose (fp3);
fclose (fp4);
fclose (fp5);
getchar();
exit(0);
}