aboutsummaryrefslogtreecommitdiff
path: root/7.4/mscanf.c
blob: 8f09f35654156d17166c23fc0a875e4ef318fc6c (plain) (blame)
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
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include "mscanf.h"

#define MAXFMT 100

void mscanf(char *fmt, ...)
{
	va_list ap;
	int i;
	char lfmt[MAXFMT];

	va_start(ap, fmt);
	for (; *fmt; fmt++) {
		if (isblank(*fmt)) {
			continue;
		} else if (*fmt != '%') {
			if (*fmt == getchar())
				continue;
			else
				break;
		}

		i = 0;
		while (i < MAXFMT && !isalpha(lfmt[i++] = *fmt++))
			;
		lfmt[i] = '\0';
		scanf(lfmt, va_arg(ap, void *));

		fmt--;
	}
	va_end(ap);
}