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);
}