Riccardo88
06-05-2013, 16:51
Domanda banale, ma in C non mi viene e non capisco perchè.
In pratica devo soltanto inserire una stringa in un campo di una struct.
#define NMAX 30
typedef struct{
char nome[ NMAX ];
char cognome[ NMAX ];
int matricola;
}studente;
void leggiStruttura( studente s );
void stampaStruttura( studente s );
--------------------------------------------- Header ---
void leggiStruttura( studente s )
{
printf("Inserisci i dati dello studente:\n");
printf("Nome: ");
scanf( "%s", &s.nome );
printf("Cognome: ");
scanf( "%s", &s.cognome );
printf("Matricola: ");
scanf( "%d", &s.matricola );
}
void stampaStruttura( studente s )
{
printf("Stampo i dati dello studente:\n");
printf("Nome: ");
printf( "%s\n", &s.nome );
printf("Cognome: ");
printf( "%s\n", &s.cognome );
printf("Matricola: ");
printf( "%d\n", &s.matricola );
}
------------------------------ .c ---
#include "libretto20Esami.h"
int main(int argc, char *argv[])
{
studente mioStudente;
leggiStruttura( mioStudente );
stampaStruttura( mioStudente );
printf("\n\n");
system("PAUSE");
return 0;
}
Dov'è l'errore ? :confused:
Tnx.
In pratica devo soltanto inserire una stringa in un campo di una struct.
#define NMAX 30
typedef struct{
char nome[ NMAX ];
char cognome[ NMAX ];
int matricola;
}studente;
void leggiStruttura( studente s );
void stampaStruttura( studente s );
--------------------------------------------- Header ---
void leggiStruttura( studente s )
{
printf("Inserisci i dati dello studente:\n");
printf("Nome: ");
scanf( "%s", &s.nome );
printf("Cognome: ");
scanf( "%s", &s.cognome );
printf("Matricola: ");
scanf( "%d", &s.matricola );
}
void stampaStruttura( studente s )
{
printf("Stampo i dati dello studente:\n");
printf("Nome: ");
printf( "%s\n", &s.nome );
printf("Cognome: ");
printf( "%s\n", &s.cognome );
printf("Matricola: ");
printf( "%d\n", &s.matricola );
}
------------------------------ .c ---
#include "libretto20Esami.h"
int main(int argc, char *argv[])
{
studente mioStudente;
leggiStruttura( mioStudente );
stampaStruttura( mioStudente );
printf("\n\n");
system("PAUSE");
return 0;
}
Dov'è l'errore ? :confused:
Tnx.