Help regarding Bus Errors
Hi, it's my first post. I'm a computer engineering student from Italy, and I'm currently studying C.
I'm preparing for my exam and often get problems regarding lists and bus errors. The function is supposed to load data from a text file into an array of list. It gives me a bus error and no futher explanation.
Code:
void inserisciDati(P_NodoLista vettore[32]){
char nomefile[30];
int day;
P_NodoLista pcorr, p;
printf("\nInserisci nome file: ");
gets(nomefile);
FILE *fp;
if ((fp=fopen(nomefile,"r"))==NULL)
exit(1);
do{
P_Misura aus = (P_Misura)malloc(sizeof(Misura));
fscanf(fp, "%d %s %d %d\n", aus->giorno, aus->citta, aus->tmax, aus->tmin);
day = aus->giorno;
p = (P_NodoLista)malloc(sizeof(NodoLista));
pcorr = vettore[day];
while(pcorr!=NULL) {
pcorr = pcorr->next;
}
pcorr->next = p;
p->info.giorno;
p->info.citta;
p->info.tmax;
p->info.tmin;
p->next = NULL;
} while (!feof(fp));
}
If it can be usefull the struct I use is:
Code:
typedef struct misura {
int giorno;
char citta[20];
int tmax;
int tmin;
} Misura, *P_Misura;
typedef struct nodolista {
Misura info;
struct nodolista* next;
} NodoLista, *P_NodoLista;
I have got often this error when dealing with lists, so I believe the must be something I constantly do wrong. Thank you for the attention, greetings from Italy :)
Ps: tell me if it can help translating the variables names to English.