码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • IO-DAY1


    1.用fprintf将链表数据保存到文件中

    2用fscanf将文件中数据写入链表

    #include<stdio.h>
    #include
    #include<stdlib.h>
    #include
    typedef int datatype;
    typedef struct link_list
    {
        union
        {
            int len;
            datatype data;
        };
        struct link_list *next; 
    }link_list,*link_p;
    link_p create_head()
    {
        link_p L = (link_p)malloc(sizeof(link_list));
        if(L==NULL)
        {
        printf("空间申请失败\n");
        return NULL;
        }
        L->len=0; 
        L->next=NULL;  
        return L;
    }
    //创建结点
    link_p create_node(datatype data)
    {

        link_p new = (link_p)malloc(sizeof(link_list));
        if(new==NULL)
        {
        printf("空间申请失败\n");
        return NULL;
        }
        new->data = data;
        return new;  
    }
    //头插
    void insert_head(link_p H,datatype data)
    {
        if(H==NULL)
        {
        printf("入参为空,请检查\n");
        return;
        }
        link_p new = create_node(data);
        new->next = H->next;  
        H->next = new;
        H->len++;
    }
    void out_put_link(link_p H)
    {
        if(H==NULL)
        {
            printf("入参为空,请检查\n");
            return;
        }
        link_p p = H->next;  
        while(p!=NULL)
        {
            printf("%d->",p->data);
            p = p->next;
        }
        printf("NULL\n");
    void save(char *filename)
    {
        FILE *w=fopen(filename,"w");
        if (w == NULL)
        {
            return 1;
        }
        link_p p=H->next;
        for (int i = 0; i len; i++) 
        {
            fprintf(w,"%d",p->data);
            p=p->next;
        }
        fclose(w);
    }void show(char *filename)/*输出文件*/
    {
        FILE *fp=fopen(filename,"r");
        link_list arr[100];
        if (fp== NULL)
        {
            return 1;
        }
        for (int i = 0; i len; i++)
        {
            fscanf(fp,"%d",&(arr[i].data));
            printf("%d\n", arr[i].data);
        }
        fclose(fp);
    }
    int main(int argc, char *argv[])
    {
        link_p H=create_head();
        insert_head(H,1);
        insert_head(H,3);
        insert_head(H,5);
        insert_head(H,7);
        insert_head(H,9);
        out_put_link(H);
        save(filename);
        free(p);
        show(filename);
          return 0;
    }
     

  • 相关阅读:
    一个好用的k8s代理工具——KtConnect
    IDEA07:Mybatis和Springboot操作数据库
    SOLR分组聚合的相关技巧
    通达信指标接口的代码测试
    git方面的知识
    网络资源模板--基于 Android Studio 实现的天气预报App
    多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
    自制操作系统系列(一):显示hello world开始旅程
    【毕业设计】基于javaEE+SSH+oracle的健康管理系统设计与实现(毕业论文+程序源码)——健康管理系统
    【Python机器学习】零基础掌握SpectralCoclustering聚类
  • 原文地址:https://blog.csdn.net/qq_60519264/article/details/136381196
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号