开发者社区> 问答> 正文

求大神解惑!一个小程序运行不了

#include 
#include 
struct data
{
int day,month,year;
} ;
struct stu 
{
char name[20];
long num;
struct data birthday;
} ;
int main()
{
struct stu *student; 
student=malloc(sizeof(struct stu)); 
printf("Input name,number,year,month,day:/n");
scanf("%s",student->name);
scanf("%ld",&student->num);
scanf("%d%d%d",&student->birthday.year,&student->birthday.month,
&student->birthday.day);
printf("/nOutputname,number,year,month,day/n");
printf("%20s%10ld%10d//%d//%d/n",student->name,student->num,
student->birthday.year,student->birthday.month,
student->birthday.day);
return 0;
}

程序怎么出错了,求大神解答!!
错误报告是这样的。
E:c++稿子sdas.cpp(16) : error C2440: '=' : cannot convert from 'void ' to 'struct stu *' Conversion from 'void' to pointer to non-'void' requires an explicit cast 执行 cl.exe 时出错.

展开
收起
a123456678 2016-03-20 14:53:11 2096 0
2 条回答
写回答
取消 提交回答
  • hello world!

    2019-07-17 19:09:45
    赞同 展开评论 打赏
  • 首先 ,只看到了 malloc 没有看到free。student=malloc(sizeof(struct stu)); 这里有问题,应该改为 ,student=(stu*)malloc(sizeof(struct stu));而且没有进行判断,万一内存不够用,无法申请到内存怎么处理。容易造成内存泄露

    2019-07-17 19:09:45
    赞同 展开评论 打赏
问答分类:
C++
问答地址:
问答排行榜
最热
最新

相关电子书

更多
《云市场-小程序》 立即下载
数字乡村建设方案 立即下载
mPaaS 小程序新品发布 立即下载