c语言fopen的问题

来源:百度知道 编辑:UC知道 时间:2024/09/21 05:37:02
我想用 if(fopen("D:\\book\\data.txt","r")== NULL)
判断data.txt文件是否存在
为什么一运行就内存错误?

源代码附下 (写了一半)
********************************
#include <stdlib.h>
#include <stdio.h>

#define MAX_NAME_SIZE 20
#define MAX_PUBLISHER_SIZE 50

struct book
{
int book_number;
int amount;
int remain;
char book_name[MAX_NAME_SIZE];
char writer[MAX_NAME_SIZE];
char publisher[MAX_PUBLISHER_SIZE];
};

int add(void);
int borrow(char book_name[]);
int give_back(char book_name[]);
void display_book_list(void);
void menu(void);

int main(void)
{

char select;
char name[MAX_NAME_SIZE];

menu();

while(true)
{
printf("请选择:");
scanf("%c",&select);
fflush(stdin);
switch(select)
{
case '1':
display_book_lis

至少改成 if((fp = fopen("D:\\book\\data.txt","r")) == NULL)

先把基本逻辑和语法学好

情况说清楚一点 到底哪一步操作有错误 说清楚一点

FILE指针没指向fopen打开的流
if(fopen("D:\\book\\data.txt","r")== NULL) //这一句
你定义的fp没指向它 改一下 if(fp=fopen("D:\\book\\data.txt","r")== NULL)

怎么后面book\\data.txt有两个反斜杠
应该是一个吧