为什么输不出姓别?
#include<Stdio.h>void main()
{
struct student
{
int num;
char *name;
char *sex;
}student;
student.num=22;
student.name="dfdsf";
student.sex="man";
printf("学号 %d\n姓名 %s\n性别 %c\n",student.num,student.name,student.sex);
}
#include<Stdio.h> #include <string.h> void main() { struct student { int num; char name[20]; char sex[20]; }student; student.num=22; strcpy(student.name,"dfdsf"); strcpy(student.sex,"man"); printf("学号 %d\n姓名 %s\n性别 %s\n",student.num,student.name,student.sex); }楼主这样做是很危险的 不给指针赋值 如果输入姓名的话程序是要崩溃的 如下图所示