求助:编译时出现error C2440
程序代码:
#include"stdio.h" #include"stdlib.h" #include"malloc.h" //输入一个结构体类型变量的成员,并输出 struct data { int day,month,year; }; struct stu { char name[20]; long num; struct data birthday; }; 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("%20s%10ld%10d//%d//%d\n",student->name,&student->num,&student->birthday.year,&student->birthday.month,&student->birthday.day); }编译时出现如下错误:
--------------------Configuration: as - Win32 Debug--------------------
Compiling...
a.cpp
E:\C练习\as\a.cpp(17) : error C2440: '=' : cannot convert from 'void *' to 'struct stu *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
E:\C练习\as\a.cpp(23) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.
a.obj - 1 error(s), 0 warning(s)
请大家给我指点下,谢谢!Compiling...
a.cpp
E:\C练习\as\a.cpp(17) : error C2440: '=' : cannot convert from 'void *' to 'struct stu *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
E:\C练习\as\a.cpp(23) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.
a.obj - 1 error(s), 0 warning(s)