I have an assigment, where I have to find the frequency of each characters in a text file, the problem is that my first lenguaje is spanish so the text fila has accented characters like "á" and I have to count "á" like "a", my code is :
int main(){
int c;
FILE *file;
file = fopen("prueba.txt", "r");
int letters[27] = {0};
if (file){
while ((c=getc(file)) !=EOF )
{
if( ((c-65) >=0 && (c-65) <= 25)){
letters[c-65]++;
}
else if( (c-97) >=0 && (c-97) <= 25){
letters[c-97]++;
}
else if( c ==181 || c== 160){ //a
letters[0]++;
}
else if( c == 130 || c== 144){//e
letters[4]++;
}
else if(c ==161 || c==214){//i
letters[8]++;
}
else if(c == 162 || c ==224){
letters[14]++;
}
else if(c ==163 || c == 233){
letters[20]++;
}
else if( c==164 || c== 165){
letters[26]++;
}
}
fclose(file);
}
}
But I found that my code read "á" like a multicharacter so c takes three values 195,161,10 and not 160, what can I do?