全站数据
8 4 2 0 5 8 1

C语言单向链表中如何往文件里存入数据和读取数据

自学习 | 简单学习,快乐成才!         
问题更新日期:2024-11-13 01:39:21

问题描述

C语言单向链表中如何往文件里存入数据和读取数据,在线求解答
精选答案
最佳答案

花了我半个小时,给了写了一个简单的例子,以下是在vs2005下调试成功,test.txt为文件名,在当前目录下。

#include <stdio.h>

#include <stdlib.h>

#define TRUE 1

#define FALSE 0

typedef struct Node

{

int num;

int score;

struct Node* next;

}Node, *Linklist;

void InitLinklist(Linklist* L) //初始化单链表,建立空的带头结点的链表

{

*L = (Node*)malloc(sizeof(Node));

(*L)->next = NULL;

}

void CreateLinklist(Linklist L) //尾插法建立单链表

{

Node *r, *s;

r = L;

int iNum, iScore;

printf(

"Please input the number and score:

");

scanf(

"%d