-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
58 lines (53 loc) · 1.36 KB
/
Copy pathmain.c
File metadata and controls
58 lines (53 loc) · 1.36 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <stdlib.h>
#include "all_thingies.h"
#include <string.h>
table_row *row = NULL;
int columns = 0;
int rows = 0;
char **master_memory_headers = NULL;
int main(int argc, char *argv[])
{
if (argc != 2) {
printf("Invalid Argument: Correct Argument Syntax: main <tablename>\n");
return 1;
}
char filename[256];
snprintf(filename, sizeof(filename), "%s.csv", argv[1]);
int n;
printf("For read, type 1 \nFor write, type 2 \n");
scanf("%d", &n);
FILE *file = fopen(filename, "r");
if (n == 1) {
if (file == NULL) {
printf("No such table exists.\n");
return 1;
}
head_reader(file);
read(file);
fclose(file);
}
else if (n == 2) {
if (file == NULL) {
printf("No such table found, creating new table...\n");
printf("Enter headers first\n");
}
else {
printf("Table found. Opening table: %s\n", filename);
head_reader(file);
fclose(file);
}
file = fopen(filename, "w");
if (file == NULL) {
printf("Unexpected error\n");
return 1;
}
write(file);
fclose(file);
}
else {
printf("Wrong argument, please try again!\n");
return 1;
}
return 0;
}