我在目录中创建了一个名为 mahmoud.txt 的文件:/Users/mahmoudhamra/Desktop/C language/
我想在 Xcode 中打开它。
我将目录和文件名分别创建为一个字符串。然后我将文件名连接到目录并尝试打开它来读取它,但它总是给我一个错误:“线程 1:信号 SIGBART”。
有人能帮助我吗?这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char * argv[]) {
FILE *inFile;
char fileName[13];
printf("enter file name: ");
scanf("%s",fileName);
char new[40]="/Users/mahmoudhamra/Desktop/C language/";
strcat(new, fileName);
inFile=fopen("new", "r");
if (inFile== NULL) {
printf("file %s was not opened!\n", fileName);
printf("check that the file exists!\n");
exit(1);
}
else
printf("the files has successfully been opened!\n");
return 0;
}