代码
#include<stdio.h>
#include<stdlib.h>
#define NAME_LEN 20
#define OTHER_LEN 120
typedef struct INFO{
char name[NAME_LEN];
char *sex;
int old;
char other[OTHER_LEN];
}info;
int main(void) {
info Ac_Info;
info *pName;
char SexChoose;
pName=(info*)malloc(sizeof(info));
Ac_Info.sex=(char *)malloc(6*sizeof(char));
printf("Input u name:");
scanf("%s",pName->name);
printf("choose u sex:Boy(b) or Gril(g):");
scanf("%s",&SexChoose);
if (SexChoose == 'b') {
Ac_Info.sex="boy";
} else if (SexChoose == 'g') {
Ac_Info.sex="gril";
} else Ac_Info.sex="unkown";
puts("Input u you age:");
scanf("%d",&Ac_Info.old);
puts("Other:");
scanf("%s",Ac_Info.other);
//name age sex other input ok,next mistake find
printf("name:%s sex:%s age:%d other:%s\n",Ac_Info.name,Ac_Info.sex,Ac_Info.old,Ac_Info.other);
}
没有提示错误但是name就是无法显示
而other却可以
结果为

谢谢 随便祝大家端午快乐
#include<stdio.h>
#include<stdlib.h>
#define NAME_LEN 20
#define OTHER_LEN 120
typedef struct INFO{
char name[NAME_LEN];
char *sex;
int old;
char other[OTHER_LEN];
}info;
int main(void) {
info Ac_Info;
info *pName;
char SexChoose;
pName=(info*)malloc(sizeof(info));
Ac_Info.sex=(char *)malloc(6*sizeof(char));
printf("Input u name:");
scanf("%s",pName->name);
printf("choose u sex:Boy(b) or Gril(g):");
scanf("%s",&SexChoose);
if (SexChoose == 'b') {
Ac_Info.sex="boy";
} else if (SexChoose == 'g') {
Ac_Info.sex="gril";
} else Ac_Info.sex="unkown";
puts("Input u you age:");
scanf("%d",&Ac_Info.old);
puts("Other:");
scanf("%s",Ac_Info.other);
//name age sex other input ok,next mistake find
printf("name:%s sex:%s age:%d other:%s\n",Ac_Info.name,Ac_Info.sex,Ac_Info.old,Ac_Info.other);
}
没有提示错误但是name就是无法显示
而other却可以
结果为

谢谢 随便祝大家端午快乐