主题:[讨论]C语言程序错误
下面的程序是自己练习用的,用VC6.0编译无错误,运行时也能出现正确结果。就是同时也出现debug assertion failed.不知道是什么问题。。
#include <stdio.h>
#include <stdlib.h>
struct stu
{
int num;
char *name;
char sex;
float score;
} boy1;
void main()
{
struct stu *boy2;
boy2=(struct stu*)malloc(sizeof(struct stu));
boy1.num=102;
boy1.name="Zhang ping";
printf("input sex and score\n");
scanf("%c,%f",&boy1.sex,&boy1.score);
boy2=&boy1;
printf("Number=%d\nName=%s\n",(*boy2).num,(*boy2).name);
printf("Sex=%c\nScore=%f",(*boy2).sex,(*boy2).score);
free(boy2);
}
#include <stdio.h>
#include <stdlib.h>
struct stu
{
int num;
char *name;
char sex;
float score;
} boy1;
void main()
{
struct stu *boy2;
boy2=(struct stu*)malloc(sizeof(struct stu));
boy1.num=102;
boy1.name="Zhang ping";
printf("input sex and score\n");
scanf("%c,%f",&boy1.sex,&boy1.score);
boy2=&boy1;
printf("Number=%d\nName=%s\n",(*boy2).num,(*boy2).name);
printf("Sex=%c\nScore=%f",(*boy2).sex,(*boy2).score);
free(boy2);
}