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

Python015

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

只需要将文件标示为二进制即可。\x0d\x0astruct student stu[256]\x0d\x0a//将stu赋值...\x0d\x0a\x0d\x0aFILE * fd=fopen("c:\\test.bin","wb")//打开\x0d\x0aint i\x0d\x0afor(i=0i 回答于 2022-11-16

#include <stdio.h>

#include <stdlib.h>

typedef struct LinkedList_st{

int key

struct LInkedList_st * next

}LinkedList

int writeList(const char* path,LinkedLIst* lst){

if(lst==NULL) return -1

FILE* file = open(path,'w+')

if(file==NULL){

printf("open file failed!")

return -1

}

LinkedList* ptr = lst

while(ptr!=NULL){

fprintf(file,"%d\n",ptr->key)ptr=ptr->next

}

close(fp)

return 1

}

随手写的,应该没错吧!自己调试下!