中国建设部网站查询网,顺德网页制作公司,软件库合集软件资料链接,wordpress search1、问题 *简化printf函数,能够处理%d, %f, %c, %s格式码,假设已经存在 *print_integer和print_float函数,另外2个类型用put char来打印 思路: void va_start(va_list ap, last);// 取第一个可变参数的指针给ap,// last是函数声明中的最后一个固定参数(比如printf函数原型…1、问题
*简化printf函数,能够处理%d, %f, %c, %s格式码,假设已经存在 *print_integer和print_float函数,另外2个类型用put char来打印 思路: void va_start(va_list ap, last);// 取第一个可变参数的指针给ap,// last是函数声明中的最后一个固定参数(比如printf函数原型中的*fromat);
type va_arg(va_list ap, type); // 返回当前ap指向的可变参数的值,然后ap指向下一个可变参数;// type表示当前可变参数的类型(支持的类型位int和double);
void va_end(va_list ap); // 将ap置为NULL 2、代码实现 #include stdio.h
#include stdarg.h/*** 简化printf函数,能够处理%d, %f, %c, %s格式码,假设已经存在* print_integer和print_float函数,另外2个类型用putchar来打印*/
void print_integer(int value)
{printf("%d", value);
}void print_float(float value)
{printf("%.1f", value);
}void my_printf(char