#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int mscanf(int n, char *buf, char *format,...)
{
char *p;
va_list argp;
va_start(argp, format);
int rc;
if ((p = buf) == NULL) {
if ((buf = malloc(sizeof(char) * n)) == NULL)
return -1;
}
fgets(buf, n, stdin);
rc = vsscanf(buf, format, argp);
if (p == NULL)
free(p);
return rc;
}
#define N 80
int main()
{
static char buff[N];
int a, b, c;
printf("> ");
printf("%d: ",mscanf(N, buff, "%d %d %d", &a, &b, &c));
printf("a = %d, b = %d, c = %d\n", a, b, c);
printf("> ");
printf("%d: ",mscanf(N, NULL, "%d %d %d", &a, &b, &c));
printf("a = %d, b = %d, c = %d\n", a, b, c);
return 0;
}
/* end */