Open wangtianrui opened 8 years ago
#include<stdio.h> #include<string.h> #define LEN sizeof(struct student) struct student { char name[20]; int num ; int score; struct student *next ; }; struct student *head , *p , *m , *x ; void shanchu(struct student *x) { struct student *ted ; int i = 1 ; char ID[20] ; printf("输入想删除学生的姓名:"); scanf("%s", ID ); ted = head ; while(ted) { if( strcmp(ted->name,ID)==0 ) { if( i == 1 ) { head = head->next ; } else { m->next = ted->next; free(ted); } } m = ted ; ted = ted->next ; i = i + 1 ; } } void shuchu( struct student *x ) { struct student *ted ; ted = head ; while(ted) { printf("%s的学号为:%d\t成绩为:%d\n", ted->name , ted->num , ted->score); ted = ted->next ; } } void creat() { p = (struct student *)malloc( LEN ) ; printf("请按照姓名,学号,分数的顺序输入。若需停止则输入 stop 0 0\n"); scanf("%s %d %d", p->name , &p->num , &p->score ); head = p ; while( strcmp( p->name , "stop") != 0 ) { m = p ; p = (struct student *)malloc( LEN ) ; scanf("%s %d %d", p->name , &p->num , &p->score ); m->next = p ; } p->next = NULL; } int main() { int i , j , n ; for( i = 1 ; i <= 100 ; i++) { printf("_"); if( i == 50 ) { printf("\n"); for( j = 1 ; j <= 16 ; j ++) { printf(" "); } printf("学生学籍管理系统"); for( j = 1 ; j <= 16 ; j ++) { printf(" "); } printf("\n"); for( j = 1 ; j <= 16 ; j++) { printf(" "); } printf("1.学生学号的添加。"); for( j = 1 ; j <= 15 ; j ++) { printf(" "); } printf("\n"); for( j = 1 ; j <= 16 ; j++) { printf(" "); } printf("2.学生学号的查看。"); for( j = 1 ; j <= 15 ; j ++) { printf(" "); } printf("\n"); for( j = 1 ; j <= 16 ; j++) { printf(" "); } printf("3.学生学号的删除。"); for( j = 1 ; j <= 15 ; j ++) { printf(" "); } printf("\n"); } } printf("\n\n\n"); for( i = 1 ; i <= 1000 ; i++) { scanf("%d", &n ); switch(n) { case 1 : creat();break ; case 2 : shuchu( head );break ; case 3 : shanchu( head );break ; default : printf("请输入正确的选项\n");continue; } } return 0 ; }
hello
学生信息管理系统