Good morning
I'm doing a frequency counter, where indicating the address of the file (txt) show which are the letters that appear and the number of times they appear in the text. The problem I have is in the counter which does not show the letters found or the number of repeated characters.
#include <iostream.h>
#include <stdio.h>
void contar(char frase[], char diccionario[], int);
int letras;
main(){
FILE *archivo;
char frase[100], diccionario[86] ="ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyz0123456789áéí[]{}/%!$&:;,.<>=?¿'" ;
int caracter,caracteres,i;
cout<<"Ingrese la direccion sin la extension (.txt):\n";
gets(frase);
strcat(frase,".txt");
archivo=fopen(frase, "r");
while((caracter = fgetc(archivo)) != EOF){
printf("%c", caracter);
letras++;
for(i=0;i<86;i++){
contar(frase, diccionario,i);
}
}
printf("\n\n\nLa cantidad de letras es: %d",letras);
fclose(archivo);
getchar();
return 0;
}
void contar(char frase[], char diccionario[],int i){
int j,num,contador;
char letra;
num = letras;
for(j=0;j<num-1;j++){
if(frase[j]==diccionario[i]){
contador+=1;
letra = diccionario[i];
}
}
if (contador !=0){
printf("el numero de letras %c es %d\n", letra, contador);
}
}
This is what the program shows me running when I use a file which has the word "anona"