结构体怎么输出是乱码?(大神们都有被期末项目苦恼过,望帮助!)
我是新手,做期末项目。
请问,这个程序出了“增加驾考信息”正常之外,为什么其他的显示信息时,为什么都是乱码呢?
望高手解答,非常感谢!!
#include
#include
#include
int system(const char *string);
void start();
void chakan(struct STUDENT info[999],int size);
void zengjia(struct STUDENT info[999],int *size);
void shanchu(struct STUDENT info[999],int *size);
void xiugai(struct STUDENT info[999]);
struct STUDENT{
char* name;
int number;
char* kemu;
};
int main()
{char input;
FILE *data;
struct STUDENT info[999];
int size=0;
start();
while(1){
input =getchar();
switch(input){
case '#':
start();
break;
case '0':
exit(0);
break;
case '1':
start();
chakan(info,size);
break;
case '2':
start();
zengjia(info,&size);
break;
case '3':
start();
shanchu(info,&size);
break;
case '4':
start();
xiugai(info);
break;
}
}
return 0;
}
void chakan(struct STUDENT info[999],int size){
int i,j;
printf("-----------------------------查看信息------------------------\n");
printf("\t序号\t姓名\t\t考号\t\t待考科目\n");
for(i=0;i
printf("\t%d",i+1);
printf("\t%s\t",info[i].name);
printf("\t%d\t",info[i].number);
printf("\t%s\t",info[i].kemu);
printf("\n");
}
printf("-------------------------请按0-4继续操作---------------------\n");
}
void zengjia(struct STUDENT info[999],int *size){
char *str,s[50];
//struct STUDENT stu={"","",""};
str=s;
printf("-----------------------------增加信息------------------------\n");
printf("请输入姓名:\n");
scanf("%s",str);
info[*size].name=str;
printf("为了测试:%s\n",info[*size].name);//测试行
printf("请输入考号:\n");
scanf("%d",&info[*size].number);
printf("为了测试:%d\n",info[*size].number);//测试行
printf("请输入待考科目:\n");
scanf("%s",str);
info[*size].kemu=str;
printf("为了测试:%s\n",info[*size].kemu);//测试行
(*size)++;
printf("添加完成!\n");
printf("-------------------------请按0-4继续操作---------------------\n");
}
void shanchu(struct STUDENT info[999],int *size){
int index,i,j;
printf("-----------------------------删除信息------------------------\n");
printf("您要删除第几条信息?\n");
scanf("%d",&index);
for(i=index-1;i
info[i]=info[i+1];
}
(*size)--;
printf("删除成功!\n");
printf("-------------------------请按0-4继续操作---------------------\n");
}
void xiugai(struct STUDENT info[999]){
int index;
char *str,s[50];
str=s;
printf("-----------------------------修改信息------------------------\n");
printf("您要修改第几条信息?\n");
scanf("%d",&index);
printf("您要将姓名:%s修改为:\n",info[index-1].name);
scanf("%s",str);
info[index-1].name=str;
printf("您要将考号:%d修改为:\n",info[index-1].number);
scanf("%d",&info[index-1].number);
printf("您要将待考科目:%s修改为:\n",info[index-1].kemu);
scanf("%s",str);
info[index-1].kemu=str;
printf("修改成功!\n");
printf("-------------------------请按0-4继续操作---------------------\n");
}
void start(){
system("cls");
printf("-------------------------------驾考信息管理系统-----------------------\n");