ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

(C语言)简单代码实现动态链表信息管理系统

2021-12-05 17:59:56  阅读:123  来源: 互联网

标签:p2 p1 struct scanf C语言 链表 score printf 信息管理系统


功能包括输入信息,输出信息,按编号查询,按编号删除,按编号修改

代码简单易修改,容易理解

 goto实现死循环,使用不同功能,按0结束程序

界面简陋,能用就行

变量名

编号:bh 书名:  name 价格: jg 数量: sl 出版社: cbs

 

#include <stdio.h>
#include <stdlib.h>
#define LPX sizeof(struct score)
struct score
{
	int bh;
	char name[20];
	int jg;
	int sl;	
	char cbs[20];
	struct score * next;
};
int n;
struct score * ll;

struct score * insert()
{
	struct score * head;
	struct score * p1,*p2;
	n = 0;ll =  (struct score*)malloc(LPX);
	p1 =p2 =  (struct score*)malloc(LPX);
	
	scanf("%d",&p1->bh);
	scanf("%s",p1->name);
	scanf("%d",&p1->jg);
	scanf("%d",&p1->sl);
	scanf("%s",p1->cbs);
	head =NULL; 
	while(p1->bh!=0)
	{
		n = n+1;
		if (n == 1) head = p1;
		else p2->next = p1;
		p2 = p1;
	p1 = (struct score*)malloc(LPX);
	scanf("%d",&p1->bh);
	scanf("%s",p1->name);
	scanf("%d",&p1->jg);
	scanf("%d",&p1->sl);
	scanf("%s",p1->cbs);
		
		
		
	}p2->next = NULL; 
	ll->next = head;
	return(head);
}
void output (struct score *head){
	struct score *p;
	p = ll->next;
	printf("\t编号\t书名\t价格\t数量\t出版社\n");
	if (ll!=NULL)
		do {
			printf("\t%d\t%s\t%d\t%d\t%s\n",
   			p->bh, p->name,p->jg, p->sl,p->cbs);
   			p = p->next;
		}while(p!=NULL);
	else printf ("没有任何信息\n");
}
void search (struct score *head){
	int j; int k = 0;int f;
	scanf("%d",&f);
	struct score *p;
	p = ll->next;
	for (j=0;j<n;j++)
	{
		if (p->bh==f){
			printf("\t编号\t书名\t价格\t数量\t出版社\n");
			printf("\t%d\t%s\t%d\t%d\t%s\n",
   			p->bh, p->name,p->jg, p->sl,p->cbs);
   			break;
		}else {
		k++;
		p = p->next;
		}
    }
	if (k==n){
		printf("没有此编号\n");
	}

}
void sc (struct score *head){
	int f;
	scanf("%d",&f);
	struct score *p1,*p2;
	p1 = ll;
	p2 = ll->next;
	while(p2->bh!=f){
		p1 = p2;
		p2= p2->next;
	}
	p1->next = p2->next;
	}
void xg (struct score *head){
	int j; int k = 0;int f;
	scanf("%d",&f);
	struct score *p,*p1,*p2;
	p = ll;
	p1 = ll->next;
	for (j=0;j<n;j++)
	{
		if (p1->bh==f)
		{
			p2 = (struct score*)malloc(LPX);
			printf("\t输入修改后的书籍档案\n");
			printf("编号\t书名\t价格\t数量\t出版社\n");
			scanf("%d",&p2->bh);
			scanf("%s",p2->name);
			scanf("%d",&p2->jg);
			scanf("%d",&p2->sl);
			scanf("%s",p2->cbs);
			p ->next = p2;
			p2 ->next = p1->next;
   			break;
		}
		else {
		k++;
		p = p1;
		p1 = p1->next;
		}
    }
    
	if (k==n){
		printf("没有此编号\n");
	}
    
}
int main()
{
	printf("\t\t\t\t----------------------------------\n"); 
	printf("\t\t\t\t\t欢迎来到图书管理系统\n");
	printf("\t\t\t\t----------------------------------\n");
	lpx:{
	int a; 
	printf("-->输入新信息请输入1,输出请输入2,按编号查询请输入3,按编号删除请输入4,按编号修改请输入5,退出请输入0\n");
	printf("-->") ;
	scanf("%d",&a);
	switch(a){
		case 0:
			break;
		case 1:
			printf("\t请按下列格式输入(中间用空格或换行分割),结束请输5次0\n"); 
			printf("编号\t书名\t价格\t数量\t出版社\n");
			insert();
			goto lpx;
		case 2:
			output(ll);
			goto lpx;
		case 3:
			printf("查询:请输入编号");
			search(ll);
			goto lpx;
		case 4:
			printf("删除:请输入编号");
			sc(ll);
			goto lpx;
		case 5:
			printf("修改:请输入编号");
			xg(ll);
			goto lpx;
		default:
			printf("不是1,2,3,4,5,0\n");
			goto lpx;
	} 
	}
	
   	return 0;
}

标签:p2,p1,struct,scanf,C语言,链表,score,printf,信息管理系统
来源: https://blog.csdn.net/lpx99/article/details/121732495

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有