#include <stdio.h>
int main()
{
int no;
int i;
printf("請輸入學生學號:");
scanf("%d",&no);
for (i = 0; i < 3; i++)
{
if (no == stu[i].no)
{
printf("學號\t 姓名\t 月\t 日\t 年\t 性別\t 成績\n");
printf("%d\t %s\t %d\t %d\t %d\t %d\t %d",stu[i].no, stu[i].name, stu[i].birthday.month, stu[i].birthday.day, stu[i].birthday.year, stu[i].sex, stu[i].score);
break;
}
}
getchar();
getchar();
return 0;
}
struct date
{
int month;
int day;
int year;
};
struct student
{
int no;
char name[20];
struct date birthday;
int sex;
int score;
};
struct student stu[3] = {
{3,"zhangsan",12,5,2015,1,23},
{1,"zhangyi",1,3,2013,2,27 },
{2,"zhanger",10,8,2016,1,25 }
};


圖片中顯示了報錯的內容
我明明是按照書上打下來的代碼,為什么總是報錯,實在是找不到問題所在
uj5u.com熱心網友回復:
把struct date
{
int month;
int day;
int year;
};
struct student
{
int no;
char name[20];
struct date birthday;
int sex;
int score;
};
struct student stu[3] = {
{3,"zhangsan",12,5,2015,1,23},
{1,"zhangyi",1,3,2013,2,27 },
{2,"zhanger",10,8,2016,1,25 }
};
這部分移動到main函式的上面,否則main函式沒法使用這些結構體和stu變數,也就是先宣告再使用,必須保證宣告再main函式之前。
uj5u.com熱心網友回復:
main函式上面沒有宣告,就和在main里面呼叫函式一個問題uj5u.com熱心網友回復:
明白了
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/98869.html
標籤:C語言
上一篇:菜雞求助資料結構,逆序數建立鏈表
