I have created a file called mahmoud.txt in the direceotry: /Users/mahmoudhamra/Desktop/C language/
I want to open it in Xcode.
I created the directory and the name of the file into a string each. Then I concatenated the file name to the directory and tried to open it to read it but it always gives me an error: "Thread 1: signal SIGBART".
Can someone help me please? Here is my code:
#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;
}