简单学生信息管理系统的升级(双向循环链表+文件IO)C语言

这篇博客承接上一篇(https://blog.csdn.net/qq_41861442/article/details/99077592)加入了文件IO,每个简单程序都会面临这样的问题,数据无法保存,再次进入,数据全没了,那么我们就需要运用到文件IO的知识了,(没有数据库,bro)

在这里插入代码片#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
typedef struct node
{
	int id_num;//teacher or student's number
	char status;//teacher : t , student : s
	int chinese;
	int math;
	int English;
	int passwd;
	char address[64];
	char sex;//man : m , women : w
	struct node *next;
}*listnode;

listnode listnode_init()
{
	listnode head = malloc(sizeof(struct node)); //申请头结点空间
	if(head == NULL)
	{
		perror("list init error");
		return NULL;
	}
	head->next = NULL;
	return head;//返回头结点地址
}

void data_init(listnode newnode ,int id_num,char status,int chinese,int math ,int English , int passwd,char * address,char sex)
{
	newnode->id_num = id_num;
	newnode->status = status;
	newnode->chinese = chinese;
	newnode->math = math;
	newnode->English = English;
	newnode->passwd = passwd;
	strcpy(newnode->address,address);
	newnode->sex = sex;
}

bool add_node(listnode head,int id_num,char status,int chinese,int math ,int English , int passwd,char * address,char sex)
{
	listnode newnode = malloc(sizeof(struct node));
	if(newnode == NULL)
	{
		perror("malloc newnode error");
		return -1;
	}
	//2、初始化节点数据
    data_init(newnode ,id_num,status,chinese,math ,English,passwd,address,sex);
    	
	//3找到链表尾部
	listnode p = head;
	while(p->next != NULL)  //如果p->next不等于 NULL,证明后面还有节点
	{
		p = p->next;	
	}
	newnode->next = p->next;
	p->next = newnode;	
	printf("尾插法所接入的数据 %d,%c\n", p->next->id_num,p->next->status);
    return true;
}

listnode search_member_prev(listnode head ,int id_number)
{
	listnode tmp = head ;
	while(tmp->next != NULL)
	{
		if(tmp->next->id_num == id_number)
		{
			return tmp ;
		}	
        tmp = tmp->next;		
	}
	return NULL;
}

//传入头节点,和另一个节点
//函数中输入 id_num 和 passwd,若匹配,返回true
listnode login_in(listnode head,listnode newOne)
{
	int passwdInput,id_num;
	listnode new = head;
	printf("please input your id_num(five Number): ");
	if(scanf("%d",&(id_num)) == 1)
	{
		while(getchar() != '\n');
		listnode tmp = search_member_prev(head,id_num);
	    if(tmp != NULL)
		{
			printf("please input your password :");
			scanf("%d",&passwdInput);
			while(getchar() !=
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值