aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fscanf1.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/fscanf1.c')
-rw-r--r--tests/fscanf1.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/fscanf1.c b/tests/fscanf1.c
new file mode 100644
index 0000000..366ea89
--- /dev/null
+++ b/tests/fscanf1.c
@@ -0,0 +1,36 @@
+#include <err.h>
+#include <stdio.h>
+
+#include "maxxes-utils.h"
+
+int
+main(void)
+{
+ FILE *fp;
+ char End[100] = { '\0' };
+ char fmt[80] = { '\0' };
+ const size_t End_size = sizeof End;
+ int index = 0;
+ long int when = 0;
+
+ if ((fp = fopen("txt/stats-games.txt", "r")) == NULL)
+ err(1, "fopen");
+
+ msnprintf(fmt, sizeof fmt, "%%d %%*c %%*d %%*c %%*d %%*s %%*s %%*d "
+ "%%*d %%*d %%*d %%*s %%%zus %%ld\n", (End_size - 1));
+ puts(fmt);
+
+ do {
+ if (fscanf(fp, fmt, &index, End, &when) != 3)
+ warnx("items assigned mismatch");
+ else {
+ printf("index:\t%d\nEnd:\t%s\nwhen:\t%ld\n---\n",
+ index,
+ End,
+ when);
+ }
+ } while (!feof(fp) && !ferror(fp));
+
+ fclose(fp);
+ return 0;
+}