【发布时间】:2012-04-23 23:14:40
【问题描述】:
我可以在我的函数 ptr * Os_printf * 中打印超过 2 个参数 但我的函数只适用于 1 个参数。
例如 -->
Os_printf("Moon %d %d",55,5);
输出:
月亮 55 5
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
char db[50];
void test_1(int (*debug)())
{
debug("JOY %d %d \n",4,55);
}
volatile int (*ptr_fscreener)(char * __restrict, const char * __restrict, ...);
void Os_formater(int (*debug)() )
{
ptr_fscreener=debug;
}
void Os_printf(const char * __restrict out,void**d)
{
va_list args;
char db[50];
ptr_fscreener(db,out,d);
puts(db);
}
int main(void) {
Os_formater(sprintf);
Os_printf("Moon %d",55);
test_1(printf);
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
return EXIT_SUCCESS;
}
/******* OUTPUT For example ******/
Moon 55
JOY 4 55
!!!Hello World!!!
【问题讨论】:
-
如果你问“我如何制作我自己的可变参数函数?”,答案很简单:gnu.org/software/libc/manual/html_node/Variadic-Functions.html,但你的措辞是一个陈述,而不是一个问题,所以很难告诉。