/*
    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


This topic: Programmazione1/AA0506/PZ > WebHome > AppuntiEsercitazioni2002 > ContaCaratteri
Topic revision: r2 - 2003-10-04 - AndreaSterbini
 
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