当我运行下面的代码时,它在 linux 中失败,但在 windows 中没有问题。文件名类似于“src/文件夹/文件”
char* loadProgSource(const char* filename, size_t* finalLength)
{
char* returnStr;
FILE* file = fopen(filename, "rb");
if(file == NULL) return NULL;
fseek(file, 0, SEEK_END);
*finalLength = ftell(file);
fseek(file, 0, SEEK_SET);
returnStr = (char*) malloc(*finalLength+1);
if(fread(returnStr, sizeof(char), *finalLength, file) != *finalLength) {
fclose(file);
free(returnStr);
return NULL;
}
returnStr[*finalLength] = '\0';
return returnStr;
}