View Single Post
Old 08-02-2007, 18:01   #2
andbin
Senior Member
 
L'Avatar di andbin
 
Iscritto dal: Nov 2005
Città: TO
Messaggi: 5206
Io la funzione la farei così:
Codice:
void statistica_stringa (char *stringa)
{
    int i = 0, c = 0, len_max = 0, idx = 0, idx_max = -1;

    do {
        if (stringa[i] == ' ' || stringa[i] == '\0')
        {
            if (c > 0 && c > len_max)
            {
                len_max = c;
                idx_max = idx;
            }
            c = 0;
        }
        else
        {
            if (c == 0)
                idx = i;
            c++;
        }
    } while (stringa[i++] != '\0');

    printf ("lunghezza_max:%d, indice_max:%d\n", len_max, idx_max);
}
__________________
Andrea, SCJP 5 (91%) - SCWCD 5 (94%)
andbin è offline   Rispondi citando il messaggio o parte di esso