|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <windows.h>
#include <string.h>
#define LEN 10 //保存学生的名字
#define STU_LEN 3//5个学生
struct birday{
int year;
int munth;
int day;
};
struct student{
char name[LEN];
double value;
char xh[5];
struct birday happy;
};
void cc(const struct student money[],int n);
void mm(const struct student money[],int n);
int main (void)
{
struct student pt[STU_LEN];
int i;
char arr[10];
char ch;
printf("下面请依次输入本班同学的成绩\n");
for (i = 0;i < STU_LEN;i++)//向结构数组输入内容
{
printf("input 学号:");
gets(pt[i].xh);
printf("input 姓名:");
gets(pt[i].name);
printf("input 成绩:");
scanf("%lf",&pt[i].value);
printf("input 生日 :(year-month-day)");
scanf("%d%d%d",&pt[i].happy.year,&pt[i].happy.munth,&pt[i].happy.day);
while (getchar() != '\n')
continue;
system("cls");
}
printf("if you want find witcha student score,please enter the number");
printf("\nyou can enter 1 and 2");
printf("\n1:输入姓名查找");
printf("\n2:输入学号查找\n");
while (ch = getchar())//判断输入,调用函数,
{
if (ch == '1')
cc(pt,STU_LEN);
else if (ch =='2')
mm(pt,STU_LEN);
else
printf("input again!");
}
return 0;
}
void cc(const struct student money[],int n)
{
char a[10];
int i;
printf("请输入姓名:");
gets(a);
for (i = 0;i < n;i++)
{
if (strcmp(a,money[i].name) == 0)
{
printf("name is %s",money[i].name);
printf("\nvalue is %f",money[i].value);
printf("\nxh is %s",money[i].xh);
printf("\nbirday is %d-%d-%d",money[i].happy.year,money[i].happy.munth,money[i].happy.day);
}
}
}
void mm(const struct student mon[],int n)
{
char b[10];
int i;
printf("请输入学号:");
gets(b);
for (i = 0;i < n;i++)
if (strcmp(b,mon[i].xh) == 0)
{
printf("name is %s",mon[i].name);
printf("\nvalue is %f",mon[i].value);
printf("\nxh is %s",mon[i].xh);
printf("\nbirday is %d-%d-%d",mon[i].happy.year,mon[i].happy.munth,mon.happy.day);
}
}
//编译可以通过,内容输入完,在输入1或者2的时候不执行函数。。试了好多次,不知道哪里出了问题,求解决。。[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]
1. 函数cc mm 里加 fflush(stdin);
2. 使用struct student pt[STU_LEN]; 这是数组存放, 用下标, 几个for里面加[i]
|
|