-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
45 lines (36 loc) · 1.16 KB
/
main.c
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
/* File: main.c
* By: Alex Tong, Date: Tue Mar 11
* Last Updated: Mon Sep 15 10:58:57
*
* main file for TRST project
* Args: Optional filename
* Purpose: Sets up file handler for read_data to use
*/
/* If you want a vimrc script to automatically place my style of heading at
* the top of your files and keep the "Last Updated" up to date on a save,
* let me know, I found my old script on Github!
*/
#include <stdlib.h>
#include <stdio.h>
#include "input.h"
extern int read_data(FILE *input);
int main(int argc, char *argv[]) {
FILE *fp = NULL;
int exit_status = 0;
/* reads in data until there is an error */
if (argc > 2) { /* cannot handle more than 1 argument */
fprintf(stderr, "%s: usage: [filename]\n", argv[0]);
exit(1);
}
else if (argc == 1) /* no filename was given so use stdin */
fp = stdin;
else /* num_args == 2 so use filename */
fp = open_or_abort(argv[1], "r");
/* start main program */
exit_status = read_data(fp);
fclose(fp);
if (exit_status != 0) {
fprintf(stderr, "Aborting due to unresolvable input error\n");
}
return exit_status;
}