Improve boilerplate.
This commit is contained in:
@@ -2,10 +2,14 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define DEFAULT_FILE "input.txt"
|
||||
#define STRBUF_LEN 200
|
||||
#define ISDIGIT(X) (X >= '0' && X <= '9')
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
// Get filename as an argument, defaults to "input.txt"
|
||||
char *path = (argc > 1) ? argv[1] : "input.txt";
|
||||
// Get filename as an argument, if there is one
|
||||
char *path = (argc > 1) ? argv[1] : DEFAULT_FILE;
|
||||
|
||||
if (!path)
|
||||
{
|
||||
@@ -14,6 +18,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
FILE *file = fopen(path, "r");
|
||||
char strbuf[STRBUF_LEN] = {0};
|
||||
|
||||
if (!file)
|
||||
{
|
||||
@@ -21,7 +26,12 @@ int main(int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Code goes here
|
||||
|
||||
while (fgets(strbuf, STRBUF_LEN, file))
|
||||
{
|
||||
// Code goes here
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user