C语言中关于结构体的问题,不知道为这个程序哪里错了,它说:undefined reference to 'print'
#include<stdio.h>#include<string.h>structStudent{intnum;charname[10];doublescore[3];}...
#include<stdio.h>
#include<string.h>
struct Student
{
int num;
char name[10];
double score[3];
};
void print(struct Student);
int main()
{
struct Student stu;
stu.num=12345;
strcpy(stu.name,"Li Fung");
stu.score[0]=67.5;
stu.score[1]=89;
stu.score[2]=78.5;
print(stu);
printf("%d %s",stu.num,stu.name);
printf("%.1f %.1f %.1f\n",stu.score[0],stu.score[1],stu.score[2]);
return 0;
} 展开
#include<string.h>
struct Student
{
int num;
char name[10];
double score[3];
};
void print(struct Student);
int main()
{
struct Student stu;
stu.num=12345;
strcpy(stu.name,"Li Fung");
stu.score[0]=67.5;
stu.score[1]=89;
stu.score[2]=78.5;
print(stu);
printf("%d %s",stu.num,stu.name);
printf("%.1f %.1f %.1f\n",stu.score[0],stu.score[1],stu.score[2]);
return 0;
} 展开
1个回答
展开全部
print函数只有声明没有定义啊。
这样改:
#include<stdio.h>
#include<string.h>
struct Student
{
int num;
char name[10];
double score[3];
};
void print(struct Student);
int main()
{
struct Student stu;
stu.num=12345;
strcpy(stu.name,"Li Fung");
stu.score[0]=67.5;
stu.score[1]=89;
stu.score[2]=78.5;
print(stu);
printf("%d %s",stu.num,stu.name);
printf("%.1f %.1f %.1f\n",stu.score[0],stu.score[1],stu.score[2]);
return 0;
}
void print(struct Student stu)
{
printf("\n%d %s ",stu.num,stu.name);
printf("%.1f %.1f %.1f\n",stu.score[0],stu.score[1],stu.score[2]);
}
这样改:
#include<stdio.h>
#include<string.h>
struct Student
{
int num;
char name[10];
double score[3];
};
void print(struct Student);
int main()
{
struct Student stu;
stu.num=12345;
strcpy(stu.name,"Li Fung");
stu.score[0]=67.5;
stu.score[1]=89;
stu.score[2]=78.5;
print(stu);
printf("%d %s",stu.num,stu.name);
printf("%.1f %.1f %.1f\n",stu.score[0],stu.score[1],stu.score[2]);
return 0;
}
void print(struct Student stu)
{
printf("\n%d %s ",stu.num,stu.name);
printf("%.1f %.1f %.1f\n",stu.score[0],stu.score[1],stu.score[2]);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询