General steps for using VA macros:
Vsptr (Char * Format,...) // Remember the format here
{
Va_list argptr;
Va_start (argptr, format); // enables argptr to point to a bucket starting with format
Va_arg (argptr, type); // returns the current parameter of the parameter list pointed to by argptr, and causes argptr to point to the next parameter in the parameter list
...
Va_end (argptr); // stops, releasing the memory space occupied by argptr
}
To determine whether the parameters pointed to by argptr have been obtained:1-Number of items that can be passed2-Use functions of the vsprintf/vsnprintf series (all parameters can be removed once.End), The common usage of this function is as follows:
# Include <stdio. h>
# Include <stdarg. h>
# Define bufsize 80
Char buffer [bufsize];
Int vspf (Char * FMT,...)
{
Va_list argptr;
Int CNT;
Va_start (argptr, FMT );
CNT = vsnprintf (buffer, bufsize, FMT, argptr );
Va_end (argptr );
Return (CNT );
}
Int main (void)
{
Int inumber = 30;
Float fnumber = 90.0;
Char string [4] = "ABC ";
Vspf("% D % F % s ",Inumber, fnumber, string );
Printf ("% s/n", buffer );
Return 0;
}