主题:[求助!!急]我的课程设计 不过有点小问题 麻烦高手帮下忙
下面是我的数据结构课程设计 不过有点小问题 姓名和性别无法显示
我是小菜鸟 不知道哪里出现问题 检查了一遍感觉应该不会错的 希望高手指点一下
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
void read_func(void);
void write_func(void);
void insert_func(void);
void sort_func(void);
void delete_func(void);
void display_func(void);
void modify_func(void);
void anykey_func(void);
struct student
{
char ID[20];
char name;
char sex;
int wlscore;
int sxscore;
int yyscore;
struct student *next;
};
struct student *ptr, *head, *current, *prev;
int main(void)
{
char option1;
system("cls");
read_func();
while(1)
{
printf("*************欢迎使用学生成绩管理系统******************\n");
printf("*************************menu********************************\n");
printf("* ========================================================= * \n");
printf("* 1>输入数据 2>删除数据 * \n");
printf("* 3>显示数据 4>修改数据 * \n");
printf("* 5>退出数据 * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" 请选择操作(1-5):");
option1=getche();
printf("\n");
switch(option1)
{
case '1':
insert_func();
break;
case '2':
delete_func();
break;
case '3':
display_func();
break;
case '4':
modify_func();
break;
case '5':
exit(0);
}
}
}
void read_func(void)
{
FILE *fptr;
head=(struct student *) malloc(sizeof(struct student));
head->next = NULL;
if((fptr=fopen("slist.dat","r")) == NULL)
{
printf(" ***没有发现数据 按任意键继续...***\n");
getch();
insert_func();
}
else
{
ptr=(struct student *) malloc(sizeof(struct student));
while(fscanf(fptr, "%s %s %s %d %d %d", ptr->ID, &ptr->name, &ptr->sex, &ptr->wlscore, &ptr->sxscore, &ptr->yyscore ) != EOF)
{
sort_func();
ptr=(struct student *) malloc(sizeof(struct student));
}
fclose(fptr);
}
}
void write_func(void)
{
FILE *fptr;
fptr=fopen("slist.dat","w");
current=head->next;
while(current != NULL)
{
fprintf(fptr, "%s %s %s %d %d %d\n", current->ID, current->name, current->sex, current->wlscore, current->sxscore, current->yyscore);
current = current->next;
}
fclose(fptr);
}
void insert_func(void)
{
char swl_temp[4];
char ssx_temp[4];
char syy_temp[4];
char n_temp[4];
char x_temp[4];
ptr=(struct student *) malloc(sizeof(struct student));
printf(" 学号 : ");
gets(ptr->ID);
printf(" 姓名: ");
gets(n_temp);
printf(" 性别: ");
gets(x_temp);
printf(" 物理成绩: ");
gets(swl_temp);
printf(" 数学成绩: ");
gets(ssx_temp);
printf(" 英语成绩: ");
gets(syy_temp);
ptr->wlscore = atoi(swl_temp);
ptr->sxscore = atoi(ssx_temp);
ptr->yyscore = atoi(syy_temp);
ptr->name = atoi(n_temp);
ptr->sex = atoi(x_temp);
sort_func();
}
void sort_func(void)
{
prev = head;
current = head->next;
while ((current != NULL) && (current->wlscore > ptr->wlscore))
while ((current != NULL) && (current->sxscore > ptr->sxscore))
while ((current != NULL) && (current->yyscore > ptr->yyscore))
{
prev = current;
current = current->next;
}
ptr->next = current;
prev->next = ptr;
}
void delete_func(void)
{
char del_ID[20];
printf(" 删除资料的学生学号: ");
gets(del_ID);
prev = head;
current = head->next;
while ((current != NULL) && (strcmp(current->ID , del_ID)!=0))
{
prev = current;
current = current->next;
}
if (current != NULL)
{
prev->next = current->next;
free(current);
printf(" %s 学生资料删除成功\n",del_ID);
}
else
printf(" %s 学生资料没有发现\n",del_ID);
anykey_func();
}
void modify_func(void)
{
char ID_temp[20],n_temp[20],x_temp[20],swl_temp[4],ssx_temp[4],syy_temp[4];
printf(" 将要被修改资料的学生学号: ");
gets(ID_temp);
current=head->next;
while ((current != NULL) && (strcmp(current->ID , ID_temp)!=0))
{
prev = current;
current = current->next;
}
if (current != NULL)
{
printf(" **************************\n");
printf(" 学号 : %s\n",current->ID);
printf(" 姓名 : %s\n",current->name);
printf(" 性别 : %s\n",current->sex);
printf(" 物理成绩: %d\n",current->wlscore);
printf(" 数学成绩: %d\n",current->sxscore);
printf(" 英语成绩: %d\n",current->yyscore);
printf(" **************************\n");
printf(" 请输入该学生新的物理成绩: ");
gets(swl_temp);
current->wlscore = atoi(swl_temp);
printf(" 请输入该学生新的数学成绩: ");
gets(ssx_temp);
current->sxscore = atoi(ssx_temp);
printf(" 请输入该学生新的英语成绩: ");
gets(syy_temp);
current->yyscore = atoi(syy_temp);
printf(" %s 学生资料修改成功\n",ID_temp);
}
else
printf(" %s 学生资料没有发现\n",ID_temp);
anykey_func();
}
void display_func(void)
{
int count=0;
system("cls");
if(head->next == NULL)
{
printf(" 没有发现学生资料\n");
}
else
{
printf(" 学号 姓名 性别 物理成绩 数学成绩 英语成绩\n");
printf(" ---------------------------\n");
current=head->next;
while(current != NULL)
{
printf(" %-5s %-5s %-5s %5d %5d %5d\n", current->ID, current->name, current->sex, current->wlscore, current->sxscore, current->yyscore);
count++;
current=current->next;
if(count % 20 == 0) getch();
}
printf(" ---------------------------\n");
printf(" 发现 %s 条资料记录\n", count);
}
anykey_func();
}
void anykey_func(void)
{
printf(" 按任意键继续...");
getch();
printf("\n");
}
谢谢
我是小菜鸟 不知道哪里出现问题 检查了一遍感觉应该不会错的 希望高手指点一下
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
void read_func(void);
void write_func(void);
void insert_func(void);
void sort_func(void);
void delete_func(void);
void display_func(void);
void modify_func(void);
void anykey_func(void);
struct student
{
char ID[20];
char name;
char sex;
int wlscore;
int sxscore;
int yyscore;
struct student *next;
};
struct student *ptr, *head, *current, *prev;
int main(void)
{
char option1;
system("cls");
read_func();
while(1)
{
printf("*************欢迎使用学生成绩管理系统******************\n");
printf("*************************menu********************************\n");
printf("* ========================================================= * \n");
printf("* 1>输入数据 2>删除数据 * \n");
printf("* 3>显示数据 4>修改数据 * \n");
printf("* 5>退出数据 * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" 请选择操作(1-5):");
option1=getche();
printf("\n");
switch(option1)
{
case '1':
insert_func();
break;
case '2':
delete_func();
break;
case '3':
display_func();
break;
case '4':
modify_func();
break;
case '5':
exit(0);
}
}
}
void read_func(void)
{
FILE *fptr;
head=(struct student *) malloc(sizeof(struct student));
head->next = NULL;
if((fptr=fopen("slist.dat","r")) == NULL)
{
printf(" ***没有发现数据 按任意键继续...***\n");
getch();
insert_func();
}
else
{
ptr=(struct student *) malloc(sizeof(struct student));
while(fscanf(fptr, "%s %s %s %d %d %d", ptr->ID, &ptr->name, &ptr->sex, &ptr->wlscore, &ptr->sxscore, &ptr->yyscore ) != EOF)
{
sort_func();
ptr=(struct student *) malloc(sizeof(struct student));
}
fclose(fptr);
}
}
void write_func(void)
{
FILE *fptr;
fptr=fopen("slist.dat","w");
current=head->next;
while(current != NULL)
{
fprintf(fptr, "%s %s %s %d %d %d\n", current->ID, current->name, current->sex, current->wlscore, current->sxscore, current->yyscore);
current = current->next;
}
fclose(fptr);
}
void insert_func(void)
{
char swl_temp[4];
char ssx_temp[4];
char syy_temp[4];
char n_temp[4];
char x_temp[4];
ptr=(struct student *) malloc(sizeof(struct student));
printf(" 学号 : ");
gets(ptr->ID);
printf(" 姓名: ");
gets(n_temp);
printf(" 性别: ");
gets(x_temp);
printf(" 物理成绩: ");
gets(swl_temp);
printf(" 数学成绩: ");
gets(ssx_temp);
printf(" 英语成绩: ");
gets(syy_temp);
ptr->wlscore = atoi(swl_temp);
ptr->sxscore = atoi(ssx_temp);
ptr->yyscore = atoi(syy_temp);
ptr->name = atoi(n_temp);
ptr->sex = atoi(x_temp);
sort_func();
}
void sort_func(void)
{
prev = head;
current = head->next;
while ((current != NULL) && (current->wlscore > ptr->wlscore))
while ((current != NULL) && (current->sxscore > ptr->sxscore))
while ((current != NULL) && (current->yyscore > ptr->yyscore))
{
prev = current;
current = current->next;
}
ptr->next = current;
prev->next = ptr;
}
void delete_func(void)
{
char del_ID[20];
printf(" 删除资料的学生学号: ");
gets(del_ID);
prev = head;
current = head->next;
while ((current != NULL) && (strcmp(current->ID , del_ID)!=0))
{
prev = current;
current = current->next;
}
if (current != NULL)
{
prev->next = current->next;
free(current);
printf(" %s 学生资料删除成功\n",del_ID);
}
else
printf(" %s 学生资料没有发现\n",del_ID);
anykey_func();
}
void modify_func(void)
{
char ID_temp[20],n_temp[20],x_temp[20],swl_temp[4],ssx_temp[4],syy_temp[4];
printf(" 将要被修改资料的学生学号: ");
gets(ID_temp);
current=head->next;
while ((current != NULL) && (strcmp(current->ID , ID_temp)!=0))
{
prev = current;
current = current->next;
}
if (current != NULL)
{
printf(" **************************\n");
printf(" 学号 : %s\n",current->ID);
printf(" 姓名 : %s\n",current->name);
printf(" 性别 : %s\n",current->sex);
printf(" 物理成绩: %d\n",current->wlscore);
printf(" 数学成绩: %d\n",current->sxscore);
printf(" 英语成绩: %d\n",current->yyscore);
printf(" **************************\n");
printf(" 请输入该学生新的物理成绩: ");
gets(swl_temp);
current->wlscore = atoi(swl_temp);
printf(" 请输入该学生新的数学成绩: ");
gets(ssx_temp);
current->sxscore = atoi(ssx_temp);
printf(" 请输入该学生新的英语成绩: ");
gets(syy_temp);
current->yyscore = atoi(syy_temp);
printf(" %s 学生资料修改成功\n",ID_temp);
}
else
printf(" %s 学生资料没有发现\n",ID_temp);
anykey_func();
}
void display_func(void)
{
int count=0;
system("cls");
if(head->next == NULL)
{
printf(" 没有发现学生资料\n");
}
else
{
printf(" 学号 姓名 性别 物理成绩 数学成绩 英语成绩\n");
printf(" ---------------------------\n");
current=head->next;
while(current != NULL)
{
printf(" %-5s %-5s %-5s %5d %5d %5d\n", current->ID, current->name, current->sex, current->wlscore, current->sxscore, current->yyscore);
count++;
current=current->next;
if(count % 20 == 0) getch();
}
printf(" ---------------------------\n");
printf(" 发现 %s 条资料记录\n", count);
}
anykey_func();
}
void anykey_func(void)
{
printf(" 按任意键继续...");
getch();
printf("\n");
}
谢谢