1 typedef struct Data{
2 40 char *name;
3 41 char *IDCARD;
4 42 char *job_id;
5 43 char *length;
6 44 char *education;
7 45 char *marriage;
8 46 int local;
9 47 }Data;
10 48
11 49 typedef struct node{
12 50 Data *data;
13 51 struct node *next;
14 52 struct node *prior;
15 53 }node;
16 54
17 55 typedef struct doublelist{
18 56 node *head;
19 57 node *tail;
20 58 size_t size;
21 59 }doublelist;
22 60
 1  void inserttail2(node *newnode)
2 126 {
3 127 if(list->size == 0){
4 128 list->tail = newnode;
5 129 list->head = newnode;
6 130 }
7 131 else{
8 132 newnode->prior = list->tail;
9 133 list->tail->next = newnode;
10 134 list->tail = newnode;
11 135 }
12 136 list->size++;
13 137 }
14 void SaveInformation()
15 380 {
16 381 node *temp = list->head;
17 382 FILE *file = fopen("staff_information.txt","w");//进行追加写
18 383 if(file == NULL){
19 384 return;
20 385 }
21 386 else{
22 387 while(temp != NULL){
23 388 fprintf(file,"%s\t\t",temp->data->name);
24 389 fprintf(file,"%s\t\t",temp->data->IDCARD);
25 390 fprintf(file,"%s\t\t",temp->data->job_id);
26 391 fprintf(file,"%s\t\t",temp->data->length);
27 392 fprintf(file,"%s\t\t",temp->data->education);
28 393 fprintf(file,"%s\n\n",temp->data->marriage);
29 394 temp = temp->next;
30 395 }
31 396 fclose(file);
32 397 }
33 398 }
34 399
35 400 void ReadInformation()
36 401 {
37 402 node *temp = list->head;
38 403 FILE *file = fopen("staff_information.txt","r");
39 404 if(file == NULL){
40 405 return;
41 406 }
42 407 else{
43 408 while(!feof(file)){
44 409 node *newnode = creat_node();//此函数返回值就为一个新节点,这行代码大家可以不用在意
45 410 fscanf(file,"%s\t\t",newnode->data->name);
46 411 fscanf(file,"%s\t\t",newnode->data->IDCARD);
47 412 fscanf(file,"%s\t\t",newnode->data->job_id);
48 413 fscanf(file,"%s\t\t",newnode->data->length);
49 414 fscanf(file,"%s\t\t",newnode->data->education);
50 415 fscanf(file,"%s\t\t",newnode->data->marriage);
51 416 inserttail2(newnode);//t尾插法插入节点
52 417 }
53 418 fclose(file);
54 419 }
55 420 return;
56 421 }

附上creat_node代码原型

 1 node *creat_node(){
2 12 node *newnode;
3 13 newnode = (node *)malloc(sizeof(node));
4 14 newnode->data = (Data *)malloc(sizeof(Data));
5 15 if(newnode->data != NULL){
6 16 newnode->data->name = (char *)malloc(50 *sizeof(char));
7 17 newnode->data->IDCARD= (char *)malloc(50 *sizeof(char));
8 18 newnode->data->job_id = (char *)malloc(50 *sizeof(char));
9 19 newnode->data->length = (char *)malloc(50 *sizeof(char));
10 20 newnode->data->education = (char *)malloc(50 *sizeof(char));
11 21 newnode->data->marriage = (char *)malloc(50 *sizeof(char));
12 22 }
13 23 newnode->prior = NULL;
14 24 newnode->next = NULL;
15 25 return newnode;
16 26 }//创建一个新结点

大家照这个模板来就能解决大家的问题,顺式结构其实也几乎一样,希望能帮大家解决问题。

c语言链表从本地文件中读取和写入数据的更多相关文章

  1. 一些常用的文本文件格式(TXT,JSON,CSV)以及如何从这些文件中读取和写入数据

    TXT文件: txt是微软在操作系统上附带的一种文本格式,文件以.txt为后缀. 从txt文件中读取数据: with open ('xxx.txt') as file: data=file.readl ...

  2. Servlet从本地文件中读取图片,并显示在页面中

    import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpSer ...

  3. 从PCD文件中读取点云数据

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=84 在本小节我们学习如何从PCD文件中读取点云数据. 代码 章例1文件夹中, ...

  4. nodeks —— fs模块 —— 从流中 读取和写入数据

    Fs流读取和写入数据 使用文件流来读取大文件不会卡顿 1, 从流中读取数据 var fs = require("fs"); var data = ''; var count = 0 ...

  5. C 语言实例 - 从文件中读取一行

    C 语言实例 - 从文件中读取一行 从文件中读取一行. 文件 runoob.txt 内容: $ cat runoob.txt runoob.com google.com 实例 #include < ...

  6. java 中读取本地文件中字符

    java读取txt文件内容.可以作如下理解: 首先获得一个文件句柄.File file = new File(); file即为文件句柄.两人之间连通电话网络了.接下来可以开始打电话了. 通过这条线路 ...

  7. IOS Android支持中文与本地文件的读取写入

    转自http://www.xuanyusong.com/archives/1069 和http://www.benmutou.com/archives/2094 前几天有个朋友问我为什么在IOS平台中 ...

  8. Java将对象保存到文件中/从文件中读取对象

    1.保存对象到文件中 Java语言只能将实现了Serializable接口的类的对象保存到文件中,利用如下方法即可: public static void writeObjectToFile(Obje ...

  9. Unity3D研究院之IOS Android支持中文与本地文件的读取写

       前几天有个朋友问我为什么在IOS平台中可以正常的读写文件可是在Android平台中就无法正常的读写.当时因为在上班所以我没时间来帮他解决,晚上回家后我就拿起安卓手机真机调试很快就定位问题所在,原 ...

随机推荐

  1. Ubuntu桌面消失

    Ubuntu桌面消失 按Ctrl + Alt + F1, 切回文本模式, 输入用户名和密码登录. 重装桌面和unity: sudo apt-get update sudo apt-get instal ...

  2. Lenet车牌号字符识别+保存模型

    # 部分函数请参考前一篇或后一篇文章 import tensorflow as tf import tfrecords2array import numpy as np import matplotl ...

  3. Fetch API & cancel duplicate API & cache API

    Fetch API & cancel duplicate API & cache API const usersCache = new Map<string, User>( ...

  4. LeetCode 刷题 App / LeetCode 题解 App

    LeetCode 刷题 APP / LeetCode 题解 App 全端支持 http://leetcode-app.xgqfrms.xyz/ http://leetcode-desktop.xgqf ...

  5. React 17 发布候选版本, 没有添加新功能

    React 17 发布候选版本, 没有添加新功能 React v17.0 Release Candidate: No New Features https://reactjs.org/blog/202 ...

  6. 为什么10月上线的NGK Global即将燎原资本市场

    近日据社区透露,NGK Global将在10月全面启动,数据公开透明,人人可以参与运营监管. 现在,区块链经济已经处于爆发前夜.金融行业的探索领先一筹,而其他行业的应用正在快速展开.区块链行业应用头部 ...

  7. 多种转弯角度的PBN旁切转弯图例分析

    无论世界怎样变化,我们依然是有点阳光就灿烂.面对世界的未知,最好的状态是勇敢的去面对,努力的去生活. 今天我们继续来聊一下PBN旁切转弯. PBN转弯保护区的结构通常都与它们的转弯角度大小有关,转弯角 ...

  8. VS Code使用Git可视化管理源代码详细教程

    前言: 随着VS Code的功能和插件的不断强大和完善,它已经成为了我们日常开发中一个必不可缺的伙伴了.在之前我曾经写过一篇SourceTree使用教程详解(一个git可视化管理神器,想要了解的话可以 ...

  9. [Python] Matplotlib 图表的绘制和美化技巧

    目录 在一张画布中绘制多个图表 加图表元素 气泡图 组合图 直方图 雷达图 树状图 箱形图 玫瑰图 在一张画布中绘制多个图表 Matplotlib模块在绘制图表时,默认先建立一张画布,然后在画布中显示 ...

  10. rabbitMQ高可用方案

    普通模式 默认的集群模式,以两个节点(rabbit01.rabbit02)为例来进行说明.对于Queue来说,消息实体只存在于其中一个节点rabbit01(或者rabbit02),rabbit01和r ...