我搜索了论坛,找不到这个问题的答案.这似乎很常见,但所提到的修复都不适用.
这是我打开文件的代码:
#include <stdio.h>
#include <string.h>
void main() {
FILE *input;
char path[200];
printf("Enter the full file path and file name in the following format:"
"\nC:\\Users\\Username\\etc......\\filename.extension\n");
fgets(path, 200, stdin);
printf("%s",path);
input=fopen(path,"r");
if (input==NULL) {
perror("The following errors were encountered");
return(-1);
}
}
Run Code Online (Sandbox Code Playgroud)
printf(%s,path)正确显示我要打开的文件的路径和名称,但fopen始终返回无效参数.我也尝试在fopen中使用指向路径的指针,但这总是会使程序崩溃.
我想对一个大文件执行一些冗长的操作,这将涉及大量的搜索.(该程序的当前版本需要5个小时,并且使用fseek至少15057,456次.)因此,我希望将文件加载到ram中,而char*不是使用FILE*.char*如果我:是否可以将文件中的空字符加载到数组中:
newchar = *(pointertothearray+offset)),避免像strcpy或等操作strstr?