aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fscanf1.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2025-03-15 15:22:40 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2025-03-15 15:22:40 +0100
commit2595ecb3a8c21caedd9b1be0ddd0d13da3ed606e (patch)
treeb4cbcd31880639f0eb1b26611c4b39e5f9b1e15b /tests/fscanf1.c
parent20183de30a7f7164ac92dbc19c4e406a37f0572a (diff)
Added test
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;
+}