这是工作代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct birthdate{
int day;
int month;
int year;
}birthdate_t;
typedef struct contacto {
char name[30];
long telephone;
birthdate_t bd; // es decir, bd es de tipo struct
} contacto_t;
/* create the prototypes. Otherwise it does not work! */
contacto_t create_contact(void);
birthdate_t create_birthdate(void);
contacto_t create_contact(){ // it returns a structure type
contacto_t c1; // creates actually a blank structure y aquí abajo le meto datos
printf("Enter name: ");
fgets(c1.name, sizeof(c1.name), stdin);
char line[256];
printf("Enter telephone: ");
fgets(line, sizeof line, stdin);
if (sscanf(line, "%ld", &c1.telephone) != 1)
{
/* error in input */
}
printf("Enter birthdate");
c1.bd = create_birthdate();
}
birthdate_t create_birthdate(){
birthdate_t bd1;
char dia[4];
printf("Enter day: ");
fgets(dia, sizeof(dia), stdin);
sscanf(dia, "%d\n", &bd1.day);
char mes[4];
printf("Enter month: ");
fgets(mes, sizeof(mes), stdin);
sscanf(mes, "%d\n", &bd1.month);
char anyo[6];
printf("Enter year: ");
fgets(anyo, sizeof(anyo), stdin);
sscanf(anyo, "%d\n", &bd1.year);
return bd1;
} // end of birthdate function
main (void)
{
create_contact();
}