我对以下代码有疑问:
#include <iostream>
#include <stdio.h>
#include "ISBNPrefix.h"
using namespace std;
int main() {
FILE* file = NULL;
int area = 0, i = 0;
long s;
file = open("swagger.txt");
fscanf(file, "%ld", &s);
cout << s << endl;
}
这是 ISBNPrefix.cpp:
#include <iostream>
#include <stdio.h>
#include "ISBNPrefix.h"
using namespace std;
FILE* open(const char filename[]) {
FILE* file = NULL;
file = fopen("filename", "r");
if (file != NULL)
return file;
else return NULL;
}
我的 ISBNPrefix.h
FILE* open (const char filename[]);
而swagger.txt的内容是:123456789
当我尝试运行它来测试它是否将 123456789 复制到我的变量中时,我遇到了分段错误!