Tags:
create new tag
view all tags

/*
    Conta quante volte ogni carattere alfabetico e' presente in una
    stringa, utilizzando un array di strutture.
*/


int main ()

{
    int i,j;

    typedef struct coppia {
       char car;
       int mult;
    } Coppia;

    Coppia a[27];

    char stringa[51];


    for  (i=0; i<27; i++)
        {
        a[i].car = '\0';
        a[i].mult = 0;
        }

    printf("inserire una stringa (max 50 caratteri)\n");
    scanf ("%s", stringa);

    i=0;
    while (stringa[i] != '\0') {
        j = 0;
        while (a[j].car != stringa[i] && a[j].car != '\0')
          j++;
        a[j].car = stringa[i];
        a[j].mult++;
        i++;
    }

    for (i = 0; a[i].car != '\0'; i++)
        printf ("%c %d\n", a[i].car, a[i].mult);

    return 0;
}



-- ArcangeloTripi - 22 Nov 2002

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2003-10-04 - AndreaSterbini






 
Questo sito usa cookies, usandolo ne accettate la presenza. (CookiePolicy)
Torna al Dipartimento di Informatica
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback