-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.c
More file actions
29 lines (27 loc) · 958 Bytes
/
file.c
File metadata and controls
29 lines (27 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "file.h"
//File Handling Function to Check the Existence of the File
FILE *checkFileExistence(char *fileName, char *fileHandling_method, int createFileIfNotExist) {
while (1) {
FILE *filePointer;
filePointer = fopen(fileName, fileHandling_method);
if (filePointer == NULL) {
if (createFileIfNotExist) {
FILE *filePointer1 = fopen(fileName, "w");
fclose(filePointer1);
continue;
};
char choice[256];
printf("\nTarget file does not exist. Enter any key to continue after relocating the file.\n");
printf("[X] - To Exit\n\n");
fgets(choice, 256, stdin);
if (strlen(choice) == 2 && tolower(choice[0]) == 'x') {
exit(0);
break;
} else {
continue;
};
} else {
return filePointer;
};
};
};