How to sort words according to the recurrence of the consonants.

(sorry for the english, i'm Italian :P).

Hello, boys. I need your help.


The array chiave[21] contains 21 consonants, ordered by occurrence in a text. Then, the last five are the most frequently in the text.

The array "parole", however, contains "c" strings of characters that represent my words.

[code]
for (s=20;s>=15;b--)
{
for (i=0;i<c;i++)
{
if (parole[i][0]==chiave[s])
{
printf("%s
",parole[i]);
}
}
}
[/code]

I try to print on the screen all the words that begin with the most frequent consonant (the last element of the array-1). If the word doesn't start with that consonant, immediately proceed to the next word (increasing the variable i).


What is the problem? It works and It doesn't work at the same time !


Please, help me ! :-P

Comments

  • what are the variables b and c? I don't see where you're decrementing s at all.

    not sure if it's what you're after, but perhaps something like below will help.

    [code]
    char *parole[] = { "apple", "bunt", "Red", "box",
    "Wagon", "street", "Cabin", "ready",
    "work", "nothing", "Mirror" },
    chiave[] = "qjzxvkwyfbghmpdclsntr";

    int i, j;

    for(i=strlen(chiave)-1; i >= 0; --i) {
    for(j=0; j < sizeof(parole)/sizeof(parole[0]); ++j) {
    if(tolower(parole[j][0]) == chiave[i])
    puts(parole[j]);
    }
    }[/code]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion