Skip to content

Instantly share code, notes, and snippets.

@lattera
Created July 29, 2011 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lattera/1114387 to your computer and use it in GitHub Desktop.
Save lattera/1114387 to your computer and use it in GitHub Desktop.
Advanced Gets
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdarg.h>
int advgets(FILE *fp, char *buf, size_t sz, char *fmt, ...)
{
va_list ap;
int ret;
if (fgets(buf, sz, fp) == NULL)
return -1;
va_start(ap, fmt);
ret = vsscanf(buf, fmt, ap);
va_end(ap);
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment