0

我正在启动一个新程序,第一步是读取在以前的程序中写入的文件。程序无法在fseek()线路和fread()线路之间运行,我收到以下错误:

debug assertion failed
expression:(stream!=NULL)

我的代码如下:

#include <stdio.h>
#include <string.h>

int main (void)
{
    int m = 0;
    char stream[20];
    FILE *fp;

    /* opens a file which had data written into it in a previous program */
    fp = fopen("codetree.bin", "r");

    /* makes sure the file pointer is set at the beginning of the file */
    fseek(fp, 0, SEEK_SET);

    m = sizeof(stream);
    fread(&stream, m, 1, fp);
    /* ... */
}

如果我添加以下行来检查 fopen 是否成功:

    if (fp == NULL) {
        printf("fopen() error...%s\n", strerror(errno)); 
    }

我收到以下错误:

 no such file or directory exists

我在代码中忽略或遗漏了什么?

4

0 回答 0