哪位大神可以帮忙改一下,比较长。谢谢!
没有语法错误,但是运行的时候有乱码。#include<stdio.h>
#include<string.h>
struct date
{
int month;
int day;
int year;
};
struct tongxunlu
{
char name[10];
char sex;
char addr[10];
int age;
int num;
long int tel;
struct date birthday;
};
void shuru(struct tongxunlu a[],int n);
void xiugai(struct tongxunlu a[],int n);
void chaxun1(struct tongxunlu a[],int n);
void chaxun2(struct tongxunlu a[],int n);
void zengjia(struct tongxunlu a[],int n);
void paixu(struct tongxunlu a[],int n);
int main()
{
int n,i;
struct tongxunlu tong[20];
printf("请输入录入的学生人数n(n<=20): ");
scanf("%d",&n);
shuru(tong,n);
printf("the information: \n");
printf("姓名 性别 住址 年龄 学号 电话 生日\n");
for(i=0;i<n;i++)
printf("%s,%c,%s,%d,%d,%ld,%d,%d,%d\n",tong[i].name,tong[i].sex,tong[i].addr,tong[i].age,tong[i].num,tong[i].tel,tong[i].birthday.month,tong[i].birthday.day,tong[i].birthday.year);
xiugai(tong,n);
for(i=0;i<n;i++)
printf("%s,%c,%s,%d,%d,%ld,%d,%d,%d\n",tong[i].name,tong[i].sex,tong[i].addr,tong[i].age,tong[i].num,tong[i].tel,tong[i].birthday.month,tong[i].birthday.day,tong[i].birthday.year);
printf("按学号查询: \n");
chaxun1(tong,n);
printf("按成绩查询: \n");
chaxun2(tong,n);
zengjia(tong,n);
for(i=0;i<n;i++)
printf("%s,%c,%s,%d,%d,%ld,%d,%d,%d\n",tong[i].name,tong[i].sex,tong[i].addr,tong[i].age,tong[i].num,tong[i].tel,tong[i].birthday.month,tong[i].birthday.day,tong[i].birthday.year);
printf("按学号排序:\n");
paixu(tong,n);
for(i=0;i<n;i++)
printf("%s,%c,%s,%d,%d,%ld,%d,%d,%d\n",tong[i].name,tong[i].sex,tong[i].addr,tong[i].age,tong[i].num,tong[i].tel,tong[i].birthday.month,tong[i].birthday.day,tong[i].birthday.year);
return 0;
}
void shuru(struct tongxunlu a[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("请输入第%d个学生的信息(姓名、性别、地址、年龄、学号、电话号码、生日): \n",i+1);
scanf("%s,%c,%s,%d,%d,%ld, %d, %d, %d\n", a[i].name, &(a[i].sex), a[i].addr,&(a[i].age),&(a[i].num),&(a[i].tel), &(a[i].birthday.month), &(a[i].birthday.year), &(a[i].birthday.year));
}
}
void xiugai(struct tongxunlu a[],int n)
{
int k,b,i;
printf("修改第%d个学生的信息\n",k);
printf("%s,%c,%s,%d,%ld",&a[k].name,&a[k].sex,&a[k].addr,a[k].age,a[k].tel);
printf("输入要修改的项目(姓名(1)、性别(2)、地址(3)、年龄(4)、学号(5)、电话(6)、生日(7)): \n");
scanf("%d",&b);
switch(b)
{
case 1:
printf("输入新名字: \n");
scanf("%s",a[i].name);
break;
case 2:
printf("输入新性别: \n");
scanf("%c",&(a[i].sex));
break;
case 3:
printf("输入新地址: \n");
scanf("%s",a[i].addr);
break;
case 4:
printf("输入新年龄: \n");
scanf("%d",&(a[i].age));
break;
case 5:
printf("输入新学号: \n");
scanf("%d",&(a[i].num));
break;
case 6:
printf("输入新电话: \n");
scanf("%ld",&(a[i].tel));
break;
case 7:
printf("输入新生日: \n");
scanf("%d,%d,%d",&(a[i].birthday.month),&(a[i].birthday.day),&(a[i].birthday.year));
break;
}
}
void chaxun1(struct tongxunlu a[],int n)
{
int newnum,i;
printf("input the num: \n");
scanf("%d",&newnum);
for(i=0;i<n;i++)
{
if(newnum==a[i].num)
printf("%s,%c,%s,%d,%d,%ld,%d,%d,%d",a[i].name,a[i].sex,a[i].addr,a[i].age,a[i].num,a[i].tel,a[i].birthday.month,a[i].birthday.day, a[i].birthday.year);
}
}
void chaxun2(struct tongxunlu a[],int n)
{
int newname,i;
printf("input the name: \n");
scanf("%s", &newname);
if(strcmp(newname,a[i].name)==0)
for(i=0;i<n;i++)
{
printf("%s,%c,%s,%d,%d,%ld,%d,%d,%d",a[i].name,a[i].sex,a[i].addr,a[i].age,a[i].num,a[i].tel,a[i].birthday.month,a[i].birthday.day, a[i].birthday.year);
}
}
void zengjia(struct tongxunlu a[],int n)
{
int i=n+1;
printf("输入增加学生的信息:");
scanf("%s,%c,%s,%d,%d,%ld,%d,%d,%d",a[i].name,&(a[i].sex),a[i].addr,&(a[i].age),&(a[i].num),&(a[i].tel),&(a[i].birthday.month),&(a[i].birthday.day), &(a[i].birthday.year));
}
void paixu(struct tongxunlu a[],int n)
{
int i;
int temp;
for(i=0;i<n;i++)
if(a[i].num>a[i+1].num)
{
temp=a[i].num;
a[i].num=a[i+1].num;
a[i+1].num=temp;
}
printf("%s,%c,%s,%d,%d,%ld,%d,%d,%d",a[i].name,a[i].sex,a[i].addr,a[i].age,a[i].num,a[i].tel,a[i].birthday.month,a[i].birthday.day, a[i].birthday.year);
}