void create_stu(struct stu * l) {
struct stu * tail_l = l;
int len = 0;
while (len <= 0) {
printf("input some students: \n");
scanf("%d", &len);
}
int i;
for (i = 0; i < len; i++) {
struct stu * note = (struct stu *)malloc(sizeof(struct stu));
scanf("%d", &(note->id));
scanf("%s", note->name);
scanf("%d", &(note->b.year));
scanf("%d", &(note->b.month));
scanf("%d", &(note->b.day));
struct stu * find_n(struct stu * l, int n) {
struct stu * p = l;
int i;
for (i = 0; i < n; i++) {
if (p == NULL) {
printf("not find!\n");
return NULL;
}
p = p->next;
}
return p;
}
void insert_n(struct stu * l, int n, int id, int year, int month, int day) {
struct stu * p = find_n( l, n);
struct stu * note = (struct stu *)malloc(sizeof(struct stu));
note->id = id;
// memcpy(note->name, "xinzeng"); 怎么给note->name 赋值?
note->b.year = year;
note->b.month = month;
note->b.day = day;
note->next = p->next;
p->next = note;
}
int length(struct stu * l) {
struct stu * p = l;
int len = 0;
if (p->next != NULL) {
p = p->next;
len++;
}
return len;
}
int del_n(struct stu * l, int n) {
struct stu * pre = find_n(l, n-1);
if (pre->next == NULL) {
printf("i can not\n");
return 0;
}
struct stu * p = pre->next;
pre->next = p->next;
free(p);
return 1;
}
void print_l(struct stu * l) {
struct stu * p = l->next;
while (p != NULL) {
printf("id=%d name=%s birthday:%d year %d month %d day.\n",
p->id, p->name, p->b.year, p->b.month, p->b.day);
p = p->next;
}
}
”void insert_n(struct stu * l, int n, int id, int year, int month, int day){....} “,
void insert_n(struct stu * l, int n, int id, ”zhangsan“, int year, int month, int day) {...}
像第二行这样参数不行吧,我想能不能把”zhangsan"这个字符串通过参数传进去,有没有办法?