Improve boilerplate.

This commit is contained in:
Dylan Smith
2023-12-05 10:39:57 -05:00
parent bdc151600e
commit 86676cae61

View File

@@ -2,10 +2,14 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.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) int main(int argc, char **argv)
{ {
// Get filename as an argument, defaults to "input.txt" // Get filename as an argument, if there is one
char *path = (argc > 1) ? argv[1] : "input.txt"; char *path = (argc > 1) ? argv[1] : DEFAULT_FILE;
if (!path) if (!path)
{ {
@@ -14,6 +18,7 @@ int main(int argc, char **argv)
} }
FILE *file = fopen(path, "r"); FILE *file = fopen(path, "r");
char strbuf[STRBUF_LEN] = {0};
if (!file) if (!file)
{ {
@@ -21,7 +26,12 @@ int main(int argc, char **argv)
return 1; return 1;
} }
// Code goes here
while (fgets(strbuf, STRBUF_LEN, file))
{
// Code goes here
}
return 0; return 0;
} }