结构体不能正常输出
#include<stdio.h>#include<stdlib.h>
#include<conio.h>
typedef struct student
{
int num;
char sex;
float score;
}S;
int n=0;
int main()
{
S *p;
p=(S*)malloc(sizeof(S));
printf("please input the data:\n");
scanf("%d%c%f",&p->num,&p->sex,&p->score);
while(p->num!=0)
{
++n;
p=(S*)malloc(sizeof(S));
printf("please input the next data:\n");
getchar();
scanf("%d%c%f",&p->num,&p->sex,&p->score);
}
printf("There are %d records:\n",n);
for(int i=0;i<n;i++)
printf("%d\t%c\t%f\n",p[i].num,p[i].sex,p[i].score);
free(p);
return 0;
}
输入中间不加逗号
输入中间加逗号