これは構造体です:
typedef struct _friend {
char *firstname;
char *lastname;
char birthdate[9];
} friend;
ユーザーに文字列を入力させ、それを(または)friend
として構造体に配置する方法について混乱しています。また、ユーザーが を使用するときに 256 文字を超える文字を入力するとどうなりますか? これは私がこれまでに持っているものです...firstname
lastname
fgets
friend *f = (friend *)malloc(sizeof(friend)); //initialize f pointer to friend
char *str;
fgets(str,256,stdin);
f->firstname = (char*)malloc(sizeof(char)*(strlen(str)+1));
strcpy(f->firstname,str);