用链表实现简易版学生信息管理系统

功能

简易版
1,增加,
2,删除
3,修改
4,查看,
5,退出,
而且只有学生姓名和电话号码。

注意我修改学生信息是用的strncpy()函数,而且因为是电话号码,所以我定义的替换前11个字符。

而且我的vim没有中文输入,所以用的中文版英语,哈哈。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student 
{
	char name[20];
 	char number[20];
 	struct student *next;
};
void putstudent(struct student *new)
{
	printf("Please input the add student name:");
	scanf("%s",new->name);
   	printf("Please input the add student number:");
   	scanf("%s",new->number);
}
void add_student(struct student **head)
{
	struct student *new;
   	static struct student *tail;
   	new = (struct student*)malloc(sizeof(struct student));
   	if(new == NULL)
   	{
      		printf("space is low");
      		exit(1);
   	}
     	putstudent(new);
   	if(*head != NULL)
   	{
      		tail->next = new;
      		new->next = NULL;
   	}
   	else
   	{
      		*head = new;
     	 	new->next = NULL;
   	}
   	tail = new;
}
void delete_student(struct student **head)
{
   	char delete[20];
   	struct student *current;
   	struct student *previous;
   	printf("Please input the delete student name:");
   	scanf("%s",delete);
   	current = *head;
   	previous = NULL;
   	while(current != NULL && strcmp(current->name, delete))
   	{
      		previous = current;
      		current = current->next;
   	}
   	if(current == NULL)
   	{
      		printf("Don't find the student\n");
   	}
   	else
   	{
       		if(previous == NULL)
     		{
        		*head = current->next;
     		}
     		else
     		{
        		previous->next = current->next;
     		}
     		free(current);
   	}
 }    
void revise_student(struct student **head)
{
   	char name[20],num[20];
   	struct student *current;
   	struct student *previous;
   	printf("Please input the revise student name:");
   	scanf("%s",name);
   	current = *head;
   	previous = NULL;
   	while(current != NULL && strcmp(current->name, name))
   	{
      		previous = current;
      		current = current->next;
   	}  
   	if(current == NULL)
   	{
      		printf("Don't find the student\n");
   	}
   	else
   	{
      		printf("name:%s  ",current->name);
      		printf("number:%s\n",current->number);
      		printf("please input the revise number:");
      		scanf("%s",num);
      		strncpy(current->number,num,11); 
    	}
}
void view_student(struct student *head)
{
   	printf("--current student system-----\n");
   	while(head != NULL)
   	{
    	printf("name:%s  ",head->name);
    	printf("number:%s\n",head->number);
    	head = head->next;
   	}
}
int main(void)
{
     	int num;
     	struct student *head = NULL;
     	printf("------------------------------------\n");
     	printf("-----------student system-----------\n");
     	printf("--1,Please input the add student----\n");
     	printf("--2,Please input the delete student-\n");
     	printf("--3,Please input the revise student-\n");
     	printf("--4,View current student system-----\n");
     	printf("--5,Exit student system-------------\n");
     	printf("------------------------------------\n");
     	while(1)
    	{
        	printf("please input number:");
        	scanf("%d",&num);
        	switch(num)
        	{
             		case 1 : add_student(&head); break;
             		case 2 : delete_student(&head); break;
             		case 3 : revise_student(&head); break;
   	     		case 4 : view_student(head); break;
             		case 5 : return 0;
        	}
     	}
}

如果要加分数的话,照着我的依葫芦画瓢就行,大致一样。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值