Già che ci sono posto una mia soluzione:
codice:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STR_SIZE 20
typedef struct _Node{
char str[STR_SIZE];
struct _Node *next;
} Node;
Node* newNode(Node *previous);
int main(void){
const char *string = "lunedi martedi mercoledi giovedi venerdi. sabato domenica";
Node *root = newNode(NULL);
Node *tmpRoot = NULL;
memset(root, '\0', sizeof(Node));
tmpRoot = root;
while(*string){
Node *tmp = tmpRoot;
int i = 0;
while(*string != ' ' && *string != '.'){
tmp->str[i++] = *string++;
}
if(*string == ' ')
string++;
else if(*string == '.')
break;
tmpRoot = newNode(tmp);
}
tmpRoot = root;
while(tmpRoot != NULL){
Node *tmp = tmpRoot->next;
printf("%s\n\n", tmpRoot->str);
free(tmpRoot);
tmpRoot = tmp;
}
return EXIT_SUCCESS;
}
Node* newNode(Node *previous){
Node *node = NULL;
if((node = malloc(sizeof(Node))) == NULL){
puts("newNode");
exit(EXIT_FAILURE);
}
node->next = NULL;
if(previous)
previous->next = node;
return node;
}