源代码:
#include <stdio.h>
#include <memory.h>
#include<string.h>
#include <malloc.h>
#include <stdlib.h>
main(){
struct stu{
int num;
char *name;
char sex;
float scorce;
} *p;
#include <stdio.h>
#include <memory.h>
#include<string.h>
#include <malloc.h>
#include <stdlib.h>
main(){
struct stu{
int num;
char *name;
char sex;
float scorce;
} *p;
(struct stu*) malloc(sizeof(struct stu));
p->num =100;
p->name=”xuNiu”;
p->sex=”n”;
p->scorce=45.3;
printf(“name=%c\nnumber=%d\n”,p->name,p->num);
printf(“sex=%c\nscore=%f\n”,p->sex,p->scorce);
free(p);
}
按下f5后弹出提示框:
Run-Time Check Failure #3 – The variable “p” is being used without being initialized.
在p和*p处显示: num CXX0030: 错误: 无法计算表达式的值
name sex scorce CXX0030: 错误: 无法计算表达式的值
本人新手,找不出具体错误来,希望帮忙找一下.
解决方案
80
题主你少了个p=吧
#include <stdio.h> #include <memory.h> #include<string.h> #include <malloc.h> #include <stdlib.h> void main(){ struct stu{ int num; char *name; char sex; float scorce; } *p; p = (struct stu*) malloc(sizeof(struct stu)); p->num =100; p->name="xuNiu"; p->sex="n"; p->scorce=45.3; printf("name=%c\nnumber=%d\n",p->name,p->num); printf("sex=%c\nscore=%f\n",p->sex,p->scorce); free(p); }