求大佬指点错误,文件输出空白
//头文件
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<Windows.h>
//extern list_single * list = createList();
struct student
{
char name[20];
char sex[2];
char num[20];
float math;
};
struct list_node
{
struct student data;
struct list_node *next ;
};
typedef struct list_node list_single ;
//创建链表
list_single * createList()
{
list_single * head_Node = (list_single *)malloc(sizeof(list_single));
head_Node->next = NULL;
return head_Node;
}
//创建新结点
list_single *createNode(struct student data)
{
list_single * new_Node = (list_single *)malloc(sizeof(list_single));
new_Node->data = data;
new_Node->next =NULL;
return new_Node;
}
//遍历链表
void print_list(list_single * head_Node)
{
list_single * p_Move = head_Node->next;
printf("num\tname\tsex\tmath\n");
while(p_Move)
{
printf("%s\t%s\t%s\t%.2f\n",p_Move->data.num,p_Move->data.name,p_Move->data.sex,p_Move->data.math);
p_Move = p_Move->next;
}
printf("\n");
}
//插入新结点,头插法
void insert_Node_by_Head(list_single * head_Node,struct student data)
{
list_single * new_Node = createNode(data);
new_Node->next = head_Node->next;
head_Node->next = new_Node;
}
//结点的指定删除
void delete_Node_by_Appion(list_single * head_Node,char* num)
{
list_single * pos_Node = head_Node->next;
list_single * pos_Front = head_Node;
if(pos_Node == NULL)
{
printf("没有找到相关信息,删除失败");
}
else
{
while(strcmp(pos_Node->data.num,num))
{
pos_Front = pos_Node;
pos_Node = pos_Front->next;
if(pos_Node == NULL)
{
printf("未找到相关信息");
return;
}
}
pos_Front->next = pos_Node->next;
free(pos_Node);
}
}
//查找信息
list_single * search_Information(list_single * head_Node,char* num)
{
list_single * p_Move = head_Node->next;
if(p_Move == NULL)
return NULL;
while(strcmp(p_Move->data.num,num))
p_Move = p_Move->next;
return p_Move;
}
//读取文件
void Read_File(list_single * head_Node,char * File_Name)
{
FILE *fp;
struct student data;
fp = fopen("File_Name","r");
if(fp == NULL)
{
printf("error:打开文件失败");
exit(0);
}
while(fscanf(fp,"%s\t%s\t%s\t%f\n",&data.num,&data.name,&data.sex,&data.math) != EOF)
{
insert_Node_by_Head(head_Node,data);//结点插入链表
}
fclose(fp);
}
//文件写
void Write_File(list_single * head_Node,char * File_Name)
{
FILE *fp;
fp = fopen(File_Name,"w");
list_single * p_Move = head_Node->next;
while(p_Move)
{
fprintf(fp,"%s\t%s\t%s\t%f\n",p_Move->data.num,p_Move->data.name,p_Move->data.sex,p_Move->data.math);
p_Move = p_Move->next;
}
fclose(fp);
}
//源#include"single _list.h"
void Menu();
void Uesr_Key();
void Add_Information();
void Printf_Information();
void Deletet_Information();
list_single * list = createList();
void main()
{
Read_File(list,"1.txt");//读取文件
print_list(list);//打印链表
/*while(1)
{
Menu();
Uesr_Key();
}*/
}
文件创建没有问题,内容写入文件也成功,但是输出文件的时候却全是空白。求大佬指点,题主c语言小白,感谢大佬帮助