#include #include #include #define MAX_PARENTS 2 #define MAX_SONS 5 #define MAX 25 typedef struct _TREE{ char nome[MAX]; struct _TREE *parents[MAX_PARENTS]; struct _TREE *sons[MAX_SONS]; struct _TREE *next; int n_parents,n_sons; } TREE; TREE *head; TREE *testa=NULL; FILE *fp; char *man,*son; char caricato=0; TREE *padre,*figlio; void read_file(char *stream); TREE *search(char *stream); void free_all(void); void print_relation(char *stream); void print_tree(char *stream); void print_all(char *stream); void copia(TREE *dest,TREE *source); int main(void) { char temp[80]; char *command; char *par; strcpy(temp,"o"); while((strcmp(temp,"fine"))!=0) { printf("C:\>"); gets(temp); command=strtok(temp," "); par=strtok(NULL," "); } return 0; } void read_file(char *stream) { TREE *temp; char line[80]; caricato=1; if((fp=fopen(stream,"r"))==NULL) { printf("Frocio\n"); exit(10); } while((fgets(line,54,fp)!=NULL) && (caricato!=0)) { man=strtok(line,"#"); son=strtok(NULL," "); padre=search(man); figlio=search(son); if(((padre->n_sons)>=5) || ((figlio->n_parents)>=2)) { printf("errore\n"); free_all(); caricato=0; } else { padre->sons[padre->n_sons++]=figlio; figlio->parents[figlio->n_parents++]=padre; } } } TREE *search(char *stream) { TREE *p0=NULL,*p1,*temp; if(head==NULL) { head=(TREE*)calloc(1,sizeof(TREE)); strcpy(head->nome,stream); return head; } else { for(p1=head;p1!=NULL && (strcmp(p1->nome,stream)<=0);p1=p1->next) p0=p1; if(p0==NULL) { p0=(TREE*)calloc(1,sizeof(TREE)); strcpy(p0->nome,stream); p0->next=head; head=p0; return p0; } else { temp=(TREE*)calloc(1,sizeof(TREE)); strcpy(temp->nome,stream); p0->next=temp; temp->next=p1; return temp; } } } void free_all(void) { TREE *temp; while(head!=NULL) { temp=head; head=head->next; free(temp); } } void print_relation(char *stream) { } void print_tree(char *stream) { TREE *omp; for(omp=head;omp!=NULL && (strcmpi(omp->nome,stream)<0);omp=omp->next); if(omp==NULL || strcmpi(omp->nome,stream)>0) { printf("FUCK\n"); return; } if(testa==NULL) { testa=(TREE*)calloc(1,sizeof(TREE)); copia(testa,omp); } else { } } void print_all(char *stream) { } void copia(TREE *dest,TREE *source) { strcpy(dest->nome,source->nome); }