我有一些問題的fopen()函數C.fopen()函數返回「沒有這樣的文件或目錄」
我'解析目錄,並把所有的路徑字符數組(字符**)。之後,我應該打開所有這些文件。並且... fopen對於某些文件返回「沒有這樣的文件或目錄」。我真的不明白,爲什麼。
- 所有的路徑都是正確的。我檢查了它。
- 我有 打開這些文件的所有權限。
- 如果我從錯誤日誌中複製路徑到文件,並嘗試使用 通過我的程序打開這個文件 - 它的工作原理。
- 其他 程序不能使用這些文件(我認爲)。
我能做什麼錯?
int main(int argc, char *argv[]){
char** set = malloc(10000*sizeof(char*));
char* path = argv[1];
listdir(path, set); /* Just parse directory. Paths from the root. No problem in this function. all paths in the variable "set" are right */
int i=0;
while(i<files){ /* files is number of paths */
FILE* file = fopen(set[i++],"rb");
fseek(file, 0L, SEEK_END);
int fileSize = ftell(file);
rewind(file);
/*reading bytes from file to some buffer and close current file */
i++;
}
}
你做錯了什麼是你沒有提供[mcve] –
請顯示你的代碼。 –
調試器。打破fopen()。逐字節檢查set []數組。如果這很尷尬,請將數組元素strcpy()轉換爲本地char數組(例如filepath [256]),然後檢查它。找出路徑不正確的原因並解決它。 –