Hello, I am making a program to make a directory in a users Library folder then create a file in it. Whenever I try to make the directory I get an error and if I continue with the program i get a segmentation fault error

Here is the source Code

void newFile(void)
{
	FILE *usrFile;
	char userText[1000];
	char fileName[24];
	DIR *fileDir;
	int x;
	
	x = mkdir("~/Library/TermOS",0100);
		
	fileDir = opendir("~/Library/TermOS");
	
	x = chdir("~/Library/TermOS");
	
	printf("Enter the name of the file (with extension): ");
	scanf("%s",fileName);
	fpurge(stdin);
	usrFile = fopen(fileName, "w");
	if (!usrFile) 
	{
		printf("Error opening file\n");
		fpurge(stdin);
		main();
	}
	
	printf("Enter text to be added to the file: ");
	fgets(userText, sizeof(userText), stdin);
	fprintf(usrFile, "%s",userText);
	fclose(usrFile);
	closedir(fileDir);
	fpurge(stdin);
	main();
	
}

PS this is part of a HUGE program which is why there are all those main() function calls in there

Did you check the permission of the directories in which you are creating a new directory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.