#include
#define MAX 100
int main() {
char line[MAX]; // sto definendo l'array e memoria fissa 10
fgets(line, MAX, stdin); // gli passo il puntatore
printf("%s\n", line);
/*
char *lineptr = line;
while (*lineptr != '\0') {
printf("%c\n", *lineptr);
lineptr++;
}
*/
char *lineptr = line;
int count = 0;
int flag = 0;
while (*lineptr != '\0') {
if (*lineptr == ' ') {
if (flag == 1) {
flag = 0;
}
lineptr++;
} else {
if (flag == 0) {
flag = 1;
count++;
}
lineptr++;
}
}
lineptr = line; // reset puntatore
flag = 0; // reset del flag
/*
printf("%d\n", count); // test funzionamento
*/
char words[count];
char *wordsptr = words;
int lecters = 0;
while (*lineptr != '\0') {
if (*lineptr != ' ') {
if (flag==0) {
flag = 1;
}
lecters++;
lineptr++;
if (*lineptr == '\0') {
*wordsptr = lecters;
break;
}
} else {
if (flag == 1) {
flag = 0;
*wordsptr = lecters;
lecters = 0;
wordsptr++;
lineptr++;
} else {
lineptr++;
}
}
}
wordsptr = words;
while (*wordsptr