-1

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

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by codeguru_2009
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.