用结构体变量做函数参数无法运行,求解
#include<stdio.h>
#include<string.h>
#define FORMAT "%d\n%s\n%f\n%f\n%f\n"
struct student
{
int num ;
char name[20];
float score[3];
};
void main()
{
void print(struct student);
struct student stu;
stu.num=12345;
strcpy(stu.name,"lili");
stu.score[0]=67.5;
stu.score[1]=89;
stu.score[2]=78.6;
print(stu);
}
void print (struct student stu);
{
printf(FORMAT ,stu.num,stu.name,stu.score[0],stu.score[1],stu.score[2]);
printf("\n");
}
运行错误:warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(105) : 参见“strcpy”的声明
1>c:\users\lenovo\documents\visual studio 2010\projects\用结构体变量和指向结构体的指针作函数参数\用结构体变量和指向结构体的指针作函数参数\00.cpp(18): warning C4305: “=”: 从“double”到“float”截断
1>c:\users\lenovo\documents\visual studio 2010\projects\用结构体变量和指向结构体的指针作函数参数\用结构体变量和指向结构体的指针作函数参数\00.cpp(22): error C2447: “{”: 缺少函数标题(是否是老式的形式表?)
1>
[解决办法]
void print (struct student stu);
{
printf(FORMAT ,stu.num,stu.name,stu.score[0],stu.score[1],stu.score[2]);
printf("\n");
}
你这个位置多了个分号吧
[解决办法]
void print (struct student stu); //这里应该把“;”去掉,
{
printf(FORMAT ,stu.num,stu.name,stu.score[0],stu.score[1],stu.score[2]);
printf("\n");
}