I'm crazying because I'm not able to pass an array of structs to a function in C language.
All my code is following...
The main.c is:
Code:
#include <stdio.h>
#include <stdlib.h>
#include "funzioni.h"
int main() {
int num;
studente s[MAX];
do {
printf("Inserisci il numero di studenti da registrare: ");
scanf("%d", &num);
} while (num > MAX);
inserisci_studenti(&s, num);
visualizza_studenti(&s, num);
return 0;
}
function.h is:
Code:
#define MAX 50
typedef char STRINGA[30];
typedef struct record_studente {
STRINGA cognome;
int voto;
} studente;
void inserisci_studenti(studente[], int);
void visualizza_studenti(studente[], int);
function.c is:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "funzioni.h"
void inserisci_studenti(studente stud[], int dim) {
int i;
for (i = 0; i < dim; i++) {
printf("%d)\n", i + 1);
printf("Cognome: ");
scanf("%s", stud[i].cognome);
do {
printf("Voto: ");
scanf("%d", &stud[i].voto);
} while (stud[i].voto < 0 || stud[i].voto > 30);
}
}
void visualizza_studenti(studente stud[], int dim) {
int i;
printf("Visualizzazione degli studenti:\n");
for (i = 0; i < dim; i++) {
printf("Cognome: %s\n", stud[i].cognome);
printf("Voto: %d\n", stud[i].voto);
printf("\n");
}
}
The error messages are:
main.c: In function ‘main’:
main.c:17:3: warning: passing argument 1 of ‘inserisci_studenti’ from incompatible pointer type [enabled by default]
In file included from main.c:3:0:
funzioni.h:13:6: note: expected ‘struct studente *’ but argument is of type ‘struct studente (*)[50]’
main.c:18:3: warning: passing argument 1 of ‘visualizza_studenti’ from incompatible pointer type [enabled by default]
In file included from main.c:3:0:
funzioni.h:14:6: note: expected ‘struct studente *’ but argument is of type ‘struct studente (*)[50]’
/tmp/ccfQtYvA.o: nella funzione "main":
main.c.text+0x45): riferimento non definito a "inserisci_studenti"
main.c.text+0x59): riferimento non definito a "visualizza_studenti"
collect2: error: ld returned 1 exit status
Please help me, I'm really becoming crazy!!
Thanks in advance.
Saverio