小编Dom*_*son的帖子

fopen在C中返回无效参数

我搜索了论坛,找不到这个问题的答案.这似乎很常见,但所提到的修复都不适用.

这是我打开文件的代码:

#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中使用指向路径的指针,但这总是会使程序崩溃.

c

6
推荐指数
2
解决办法
2849
查看次数

我可以在字符串中存储NULL吗?

我想对一个大文件执行一些冗长的操作,这将涉及大量的搜索.(该程序的当前版本需要5个小时,并且使用fseek至少1505​​7,456次.)因此,我希望将文件加载到ram中,而char*不是使用FILE*.char*如果我:是否可以将文件中的空字符加载到数组中:

  1. malloc char数组,并分别存储它的长度
  2. 只对数组使用字符操作(即newchar = *(pointertothearray+offset)),避免像strcpy或等操作strstr?

c string

0
推荐指数
1
解决办法
161
查看次数

标签 统计

c ×2

string ×1