回复 19楼 TonyDeng
版主的意思是 如果要输入姓名,就必须重新为char *stu_name分配一块内存。?程序代码:
#include <stdio.h> #include <stdlib.h> #define LEN sizeof(struct stu_power) struct stu_power { char *stu_name; unsigned int power; }; int main () { struct stu_power *head; //head存放 stu_power的首地址 head = (struct stu_power *) malloc(LEN); head->stu_name = (char *) malloc(50); //为char *stu_name 分配一块内存 scanf ("%s %d", head->stu_name, &head->power); printf ("%s --> %d\n", head->stu_name, head->power); free(head); return 0; }
总有人比你努力,可怕的是比你牛的人比你还努力。