How to use vsscanf() function to read formatted data from string into variable in C

1 Answer

0 votes
#include <stdio.h>
#include <stdarg.h>

void ReadFormattedData(const char * str, const char * format, ... )
{
	va_list args;
	
	va_start(args, format);
	vsscanf(str, format, args);
	va_end(args);
}
   
int main(void)
{
	int n;
	char buf[128];

	ReadFormattedData("100 abcd", "%d %s", &n, buf);

	printf("n = %d str = %s\n", n, buf);

    return 0;
}

 
/*
run:

n = 100 str = abcd

*/

 



answered May 7, 2016 by avibootz
...