Salve a tutti, ogni volta che provo a compilare un progetto il compilatore mi da una serie di errori, ma non riesco a capire perchè (a me non sembra ci siano errori di sintassi). Vi posto per esempio il programma che sto facendo e vi sarei grato se riusciste a farmi capire cosa/dove sbaglio. Il programma non è terminato ma in teoria dovrebbe comunque potersi compilare perchè non dipende dalle parti mancanti. Grazie![]()
codice:|*TREE.H*| #ifndef _TREE_INCLUDED #define _TREE_INCLUDED #define N 50 typedef tree tree_t; void scanFile (FILE*); void descendents (char*, char*); int brothers (char*, char*); #endifcodice:|*TREE.C*| #include <stdio.h> #include <stdlib.h> #include <string.h> #include "Tree.h" typedef struct tree { char name [N]; char surname [N]; char gender; int age; int parents [2]; }; static tree_t **ar; static int n; static int desc=0; int hash (char *, char*); void scanFile (FILE *fp) { int i, index, ageTmp; char nameTmp [N], surnameTmp [N], genderTmp, fatherN [N], fatherS [N], motherN [N], motherS [N]; fscanf (fp, "%d", &n); ar= malloc (N*sizeof (tree_t*)); if (ar== NULL) { printf ("allocation error \n"); exit (-2); } for (i=0; i<n; i++) { ar [i]= malloc (sizeof (tree)); if (ar [i]== NULL) { printf ("allocation error \n"); exit (-2); } } for (i=0; i<n; i++) { fscanf (fp, "%s %s %c %d", nameTmp, surnameTmp, &genderTmp, &ageTmp); index=hash (nameTmp, surnameTmp); strcpy (ar [index]->name, nameTmp); strcpy (ar [index]->surname, surnameTmp); ar [index]->gender= genderTmp; ar [index]->age= ageTmp; } while (fscanf (fp, "%s %s %s %s %s %s", nameTmp, surnameTmp, fatherN, fatherS, motherN, motherS)!= NULL) { index= hash (nameTmp, surnameTmp); (*ar) [index]->parents [0]= hash (fatherN, fatherS); (*ar) [index]->parents [1]= hash (motherN, motherS); } } void descendents (char* name, char* surname) { int index=0, i; index= hash (name, surname); for (i=0; i<n; i++) { if ((index== ar [i]->parents [0]) || (index== ar [i]->parents [1])) { desc++; descendents (ar [index]->name, ar [index]->surname); } else return; } } int brothers (char* name, char* surname) { int index, father, mother, brotherN=0, i; index= hash (name, surname); father= ar [index]->parents [0]; mother= ar [index]->parents [1]; for (i=0; i<n; i++) { if ((ar [i]->parents [0]== father) || (ar [i]->parents [1]== mother)) { brotherN++; } } } int hash (char* name, char* surname) { return 1; }codice:|*MAIN.C*| #include <stdio.h> #include <stdlib.h> #include <string.h> #include "Tree.h" void filename (char**); char *personName (char**); char *personSurname (char**); int main () { char *name, choice, *perName, *perSurname; FILE *fp=NULL; filename (&name); fp= fopen (name, "r"); if (fp== NULL) { printf ("error opening the file\n"); return -1; } scanFile (fp); while (choice!='e') { printf ("Select an option:\n"); printf ("count descendents (a)?\n"); printf ("count longest (b)?\n"); printf ("count the longest descent (c)?\n"); printf ("count the number of brothers and sisters (c)\n?"); printf ("exit (d)?\n"); scanf ("%c", choice); switch (choice) { case 'a': descendents (personName (&perName), personSurname (&perSurname)); free (perName); free (perSurname); break; case 'b': case 'c': brothers (personName (&perName), personSurname (&perSurname)); free (perName); free (perSurname); break; case 'd': break; default: printf ("error: unknown option\n"); break; } } return 0; } void filename (char **name) { char nameTmp [N]; printf ("insert file name: "); scanf ("%s", nameTmp); (*name)= malloc (sizeof (nameTmp)); if (*name== NULL) { printf ("allocation error\n"); exit (-2); } strcpy (*name, nameTmp); return; } char *personName (char **name) { *name= malloc (N*sizeof (char)); if (*name== NULL) { printf ("allocation error \n"); exit (-2); } printf ("insert name: "); scanf ("%s", *name); return *name; } char *personSurname (char **surname) { *surname= malloc (N*sizeof (char)); if (*surname== NULL) { printf ("allocation error \n"); exit (-2); } printf ("insert surname: "); scanf ("%s", *surname); return *surname; }

 
					
					
					
						
  Rispondi quotando
						
 e "tree_t" è un tipo fatto con typedef e quindi perchè undeclared...
						
.
						