aboutsummaryrefslogtreecommitdiffstats
path: root/tests/fscanf1.c
blob: 366ea89d671f4a7775fabb0b410ffcce5e0d5c63 (plain)
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
#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;
}