當(dāng)需要對多個不同類型的數(shù)據(jù)進行統(tǒng)一處理時,可以把該數(shù)據(jù)定義為結(jié)構(gòu)體數(shù)組,最典型為成績表;
結(jié)構(gòu)體的定義:
struct stu
{
???????? int? num;
???????? char? name[10];
???????? char? s;
???????? int? cla;
???????? int? score[3];
}
student[10]={1,”zhang”,m,1,95,96,97};
Tips:結(jié)構(gòu)體數(shù)據(jù)一般定義為全局變量。
結(jié)構(gòu)體的賦值:結(jié)構(gòu)體的賦值要一一對應(yīng);
結(jié)構(gòu)體的輸出:結(jié)構(gòu)體的輸出也要一一對應(yīng),各自使用不同的輸出控制符
printf(“%d???????? %s??? %c??? %d??? %d??? %d??? %d”,student[0].num,student[0].name,student[0].s,student[0].cla,student[0].score[0],student[0].score[1],student[0].score[2]);
fflush(stdin);函數(shù)清除緩存,可以在輸入字符、字符串前使用,避免錄入混淆,尤其%s的錄入過程,應(yīng)提前使用該函數(shù)。字符串中,可以使用漢字元素,一個漢字占2個字節(jié)大小。