当前位置:   article > 正文

C语言链表模板,学生管理系统(链表数据写入文本) 。_学生管理系统c语言链表,录入txt文件

学生管理系统c语言链表,录入txt文件

链接:《c语言项目》学生成绩管理系统(devc++)

链表,学生管理系统(链表数据写入文本) 模板。

示例代码:



#include<stdio.h>
#include<stdlib.h>
#define N 4
//输入到文件的函数
void file(struct node*head);
//创建节点函数
struct node*fun();
//删除函数
void del(struct node*);
//查找函数
void find(struct node*);
//全部输出函数
struct node*output(struct node*);

 struct node
{
	int date;
	int score;
	char name[10];
	struct node *next;
};
 //首页函数
int sy()
{
	int i=1;
		printf("\t\t\t\t\t——————————————————\n");
		printf("\t\t\t\t\t*****链表各个功能实验测试		*****\n");
		printf("\t\t\t\t\t*****0.退出系统				*****\n");
		printf("\t\t\t\t\t*****1.输入数据				*****\n");
		printf("\t\t\t\t\t*****2.输出全部数据			*****\n");
		printf("\t\t\t\t\t*****3.删除数据				*****\n");
		printf("\t\t\t\t\t*****4.保存到文本		        *****\n");
		printf("请选择\n");
		scanf_s("%d",&i);
		while(1)
		{
			if(i<0||i>N)
			{
				printf("***没有此选项。请重新选择***\n");
				system("pause");
			}
			break;
		}

	return i;
}
void main()
{
	int i,j=1;
	struct node*head=NULL;
	while(j)
	{
		i=sy();
		switch(i)
		{
			case 0:
				j=0; 
				printf("退出成功");
				break;
			case 1:
				head=fun();system("pause");break;//创建节点函数
			case 2:
				head=output(head);system("pause");break;//全部输出函数
			case 3:
				del(head);system("pause");break;//删除函数
			case 4:file(head);
			default:break;
	
		}
		printf("\t\t\t\t\t——————————————————\n");
	}
	
	
	
	system("pause");
	
}
//1创建节点
struct node*fun()
{
	int i=0,j=1;
	int date;
	int score;
	char name[10];
	struct node *head,*p,*n;
	struct node *last=NULL;//尾节点
	head=p=(struct node*)malloc(sizeof(struct node));
	//printf("输入多个个学生的编号,用空格隔开,输入0按回车结束输入\n");
	//scanf("%d",&i);
	while(1)
	{

		if(j>0)
		{
			i++;
			
			n=(struct node*)malloc(sizeof(struct node));
			printf("请输入第%d个学生的学号,姓名,分数\n",i);
			scanf("%d %s %d",&n->date,&n->name,&n->score);
			p->next=n;
			p=n;
			printf("是否继续输入下一个同学的信息?输入 1 继续,输入  0  就停止输入\n");
			fflush(stdin);
			scanf("%d",&j);
			fflush(stdin);
		}
	
		else 
		{
			p->next=last;
				p=last;
			break;
		}
	}
	return head;
}
//2输出
struct node* output(struct node*head)
{
	if(head==NULL)
		printf("还没有数据请先输入数据\n");
	else
	{
	struct node *p1;
	p1=head->next;
	printf("学号\t姓名\t分数\n");
	while(p1!=NULL)
	{
		printf("%d\t%s\t%d",p1->date,p1->name,p1->score);
		p1=p1->next;
		printf("\n");
	}
	printf("\n");
	return head;
	}
}
//3删除
void del(struct node*head)
{
	int key,j=0;
	struct node*p,*s;
	s=head->next;
	p=head;
	printf("请输入你要删除的数据\n");
	getchar();//fflush(stdin) ;删除缓存的数据。
	scanf("%d",&key);
	printf("%d\n",key);
	while(s!=NULL)
	{
		if(s->date!=key)
		{
			p=s;
			s=s->next;
		}
		else
			break;	
	}
	if(s!=NULL)
	{
		p->next=s->next;
		free(s);
		printf("yes yes     yes\n");
	}
	else
		printf("no no    no\n");
}
void file(struct node*head){
	int i=0;
	FILE *fp;
	struct node*p=head->next;
	fp=fopen("C:\\Users\\Administrator\\Desktop\\112.txt","wt");

	 while(p!=NULL) 
 {
	 fprintf(fp," %d\t%s\t%d\n",p->date,p->name,p->score);
	 p = p->next;
	 i++;
 }
	 if(i>0)
		 printf("\t\t\t\t\t—————保存成功—————\n");
	 else printf("\t\t\t\t\t—————保存失败—————\n");
	fclose(fp);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/736495
推荐阅读
相关标签
  

闽ICP备14008679号