aboutsummaryrefslogtreecommitdiff
path: root/7.4/mscanf.c
diff options
context:
space:
mode:
Diffstat (limited to '7.4/mscanf.c')
-rw-r--r--7.4/mscanf.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/7.4/mscanf.c b/7.4/mscanf.c
new file mode 100644
index 0000000..8f09f35
--- /dev/null
+++ b/7.4/mscanf.c
@@ -0,0 +1,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);
+}