冯国平 2 years ago
parent bcde9bb514
commit 3e23e2b969

90
daima

@ -0,0 +1,90 @@
}
else
{
printf("学生已存在");
}
}
//修改
void update_data(void)
{
int num;
printf("输入学生学号:");
scanf("%d", &num);
int f = 0;
for (int i = 0; i < num_parts; i++)
{
if (num == stu[i].number)
{
f = 1;
break;
}
}
if (f == 0)
{
printf("学生不存在");
}
else
{
printf("输入学生学号:");
scanf("%d", &stu[num].number);
printf("输入学生姓名:");
scanf("%s", stu[num].name);
printf("输入学生成绩:");
scanf("%d", &stu[num].score);
printf("学生 %d 已更新", num);
}
}
//删除
void delete_data(void)
{
int num;
printf("输入学生学号:");
scanf("%d", &num);
int f = 0, i, j;
for (i = 0; i < num_parts; i++)
{
if (num == stu[i].number)
{
f = 1;
break;
}
}
if (f == 0)
{
printf("学生不存在");
}
else
{
for (j = i; j < num_parts - 1; j++)
{
stu[j] = stu[j + 1];
}
num_parts--;
printf("删除成功");
}
}
void read_data(void)
{
puts("读取数据");
printf("请输入文件名");
char filename[256];
scanf("%s", filename);
FILE *fp = fopen(filename, "r");
if (fp == NULL)
{
perror(filename);
return;
}
int i = 0;
while (fscanf(fp, "%d,%[^,],%d", &stu[i].number, stu[i].name, &stu[i].score) == 3)
{
i++;
}
fclose(fp);
num_parts = i;
printf("读取 %d 记录\n", num_parts);
}
Loading…
Cancel
Save