Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/08/2015, 05:15
Blast06
 
Fecha de Ingreso: julio-2015
Ubicación: San Juan
Mensajes: 7
Antigüedad: 8 años, 9 meses
Puntos: 0
Respuesta: Ordenar cantidad de repeticion de caracteres

Bueno logré ordenarlo, pero ahora no se porque diablos las letras aparecen en algunos simbolos, algo convertí mal, por favor si alguien puede ver que me pasó, miren:



este es el código:

[CODE] int main()
{
char texto[128], caracteres[256] = {0};
int i, h, mayor, elmayor;

printf("Ingrese una frase o texto: ");
gets(texto);

for(i = 0; texto[i] != '\0'; i++){
caracteres[(int)texto[i]]++;}

//Para letras
for(i = 0; i < 128; i++){
for(h=i+1; h < 128; h++){
if(texto[i]>= texto[h]){
elmayor= texto[i];
texto[i]=texto[h];
texto[h]=elmayor;}
}
}



//para numeros
for(i = 0; i<256; i++){
for(h =i+1; h <256; h++){
if(caracteres[i]>= caracteres[h]){
mayor= caracteres[i];
caracteres[i]=caracteres[h];
caracteres[h]=mayor;}
}
}






for(i = 0; i < 256; i++){
if(caracteres[i] > 0){

printf("\n%c = %d", i, caracteres[i]);}}

getchar();
getchar();
return 0;
}
[\CODE]