Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么fopen无法使用文件夹?_C_Windows_Visual Studio_File - Fatal编程技术网

C 为什么fopen无法使用文件夹?

C 为什么fopen无法使用文件夹?,c,windows,visual-studio,file,C,Windows,Visual Studio,File,这个代码有效 pFile = fopen("d:\myfile.txt", "w"); 这个代码不起作用 pFile = fopen("d:\ABC\myfile.txt", "w"); 我有这个文件夹d:\ABC OS是Windows10,使用VisualStudio2019 errno是22。这一行解决了问题: pFile = fopen("D:\ABC\\myfile.txt", "r"); microsoft文件使用 “d:\\ABC\\myfile.txt” “d:/ABC/my

这个代码有效

pFile = fopen("d:\myfile.txt", "w");
这个代码不起作用

pFile = fopen("d:\ABC\myfile.txt", "w");
我有这个文件夹d:\ABC

OS是Windows10,使用VisualStudio2019


errno是22。

这一行解决了问题:

pFile = fopen("D:\ABC\\myfile.txt", "r");
microsoft文件使用

“d:\\ABC\\myfile.txt”


“d:/ABC/myfile.txt”

你检查权限了吗?返回的错误代码是什么?请发布错误。您不应该在字符串中转义\吗,如
“d:\\ABC….”
?可能
\A
是转义序列,而
\m
不是。什么是
printf(“%s\n”,strerror(22))报告?Windows上的错误消息是什么?(在Mac和Linux上,它是
EINVAL-无效参数
;但在Windows上不一定是这样翻译的。)您也可以尝试:
printf(“名称:[[%s]]]\n”,“d:\ABC\myfile.txt”)
并查看它提供了什么。反斜杠被“删除”的可能性很高。您应该考虑<代码> PrimTf(“名称:[[%s] \n”,“d:\ab\\\MyField.txt”);
甚至
printf(“名称:[[%s]]\n”,“d:/ABC/myfile.txt”)。Windows程序API接受文件名中的斜杠;是命令提示符不喜欢它们。@Mark IMKOn没有
\m
转义序列,无论如何你不需要在意,唯一重要的是,如果你想在字符串文本中有一个
'\'
,你需要用另一个反斜杠来转义它:例如:
“Hello\\World”
;您应该转义该字符串中的两个“\”。或者-甚至更好-将反斜杠字符改为正斜杠。Windows完全能够应对这种情况。它不太容易出错,而且更易于移植。@mrfo,在大多数情况下,正斜杠是有效的,除了“\\?\”路径只有在前缀仅使用反斜杠的情况下才使用特殊的大小写来绕过规范化(到sidestep
MAX\u PATH
),在这种情况下,路径的其余部分也必须仅使用反斜杠。此外,如果定义了一点切线,
CreateProcess
需要在相对路径中使用反斜杠,例如
lpCommandLine
中的“ABC\\myfile.exe”;它找不到“ABC/myfile.exe”。
//these are all the same
char test1[]={'\n', '\a','\t','\\','\'','\"','\0'};
char test2[]={'\N', '\A','\T','\\','\'','\"','\0'};
char test3[]={10,7,9,92,39,34,0};
char test4[]={0x0a,0x07,0x09,0x5c,0x27,0x22,0x00};
char test5[]="\n\a\t\\\'\"";
char test6[]="\N\A\T\\\'\"";