You may produce the format string with sprintf():
sprintf( format, " %%%is %%%is", X, Y );
scanf(format, buf1, buf2);
EDIT: amazing, but the following gcc code is working:
#include <stdio.h>
#define LIST(...) __VA_ARGS__
#define scanf_param( fmt, param, str, args ) {
char fmt2[100];
sprintf( fmt2, fmt, LIST param );
sscanf( str, fmt2, LIST args );
}
enum { X=3 };
#define Y X+1
int main(){
char str1[10], str2[10];
scanf_param( " %%%is %%%is", (X,Y), " 123 4567", (&str1, &str2) );
printf("str1: '%s' str2: '%s'
", str1, str2 );
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…