C语言 变量重定义
发布网友
发布时间:2022-06-15 18:33
我来回答
共1个回答
热心网友
时间:2023-10-27 10:50
#include<stdio.h>
#include<stdlib.h>
struct date {
int year;
int month;
int day;
};
struct student {
long int no;
char name[20];
struct date birthday;
unsigned sex;
float score;
};
struct student mstd[3] = {//std是C++的命名空间名称,这里改为mstd。要说明的是,假如你使用标准C编译环境就没有命名冲突了,若使用C++环境则会报错。
{2013160123,"ZHANG San",1997,7,21,0,90.00},{2013160124,"LI Si",1998,8,21,1,92.00},
{2013160125,"WANG Wu",1999,2,21,0,93.00}
};
int main() {
int i;
long no;
printf("please input no:\n");
scanf("%ld",&no);
for (i = 0;i < 3;i++)
if (no == mstd[i].no) {
printf("no\t\tname\t\tyear\tmonth\tdat\tsex\tscore\t\n");
printf("%ld\t%s\t\t%d\t%d\t%d\t%u\t%.2f\t", mstd[i].no, mstd[i].name, mstd[i].birthday.year, mstd[i].birthday.month, mstd[i].birthday.day, mstd[i].sex, mstd[i].score);
break;
}
if (i == 3) printf("error!");
getchar();
getchar();
return 0;
}