第五天學習日誌
#include<string.h>
#include<stdio.h>
#include"student.h"
void menu()
{
printf("**********************************\n");
printf("1、輸入資訊 2、顯示資訊\n");
printf("3、刪除資訊 4、修改資訊\n");
printf("**********************************\n");
}
void AddInfo(stu s[])
{
printf("請輸入姓名、年齡、性別、學號:\n");
scanf("%s %d %c %d",s[i].name,&s[i].age,&s[i].sex,&s[i].number);
s[i].id=i+1;
i++;
}
void ShowInfo(stu s[])
{
int j;
for(j = 0; j < i; j++)
{
printf("學生資訊:%d\n",s[j].id);
printf("姓名 :%s\n年齡:%d\n性別:%c\n學號:%d\n",s[j].name, s[j].age,s[j].sex,s[j].number);
}
}
void DeleteInfo(stu *s)
{
int id,j;
printf("請輸出刪除學生的編號:\n");
scanf("%d",&id);
for(j = 0; j < i-id; j++)
{
s[id+j-1]=s[id+j];
s[id+j-1].id=id+j;
}
i--;
}
void ModifyInfo(stu *s)
{
int id;
printf("請輸入修改學生的編號:\n");
scanf("%d",&id);
printf("請輸入姓名、年齡、性別、學號:\n");
scanf("%s %d %c %d",s[id-1].name,&s[id-1].age,&s[id-1].sex,&s[id-1].number);
}
int main()
{
char choice[20];
stu student[SIZE] = {0};
while(1)
{
menu();
scanf("%s",choice);
switch(atoi(&choice[0]))
{
case 1:
AddInfo(student);
break;
case 2:
ShowInfo(student);
break;
case 3:
DeleteInfo(student);
break;
case 4:
ModifyInfo(student);
break;
}
}
}