代码测试----不定参函数

来源:互联网 发布:三思网络 编辑:程序博客网 时间:2024/05/06 13:40

  1. #include <stdio.h>  
  2. #include <stdarg.h>  
  3.   
  4. void MyPrintf(char *format, ...)  
  5. {  
  6.     va_list ap;  
  7.     va_start(ap, format);  
  8.     vprintf(format, ap);  
  9.     va_end(ap);  
  10. }  
  11.   
  12. void Error(char *format, ...)  
  13. {  
  14.     va_list ap;  
  15.     va_start(ap, format);  
  16.     fprintf(stdout, "err:");  
  17.     vprintf(format, ap);  
  18.     va_end(ap);  
  19. }  
  20.   
  21. int main()  
  22. {  
  23.     MyPrintf("test printf %d %s /n", 1, "hell");  
  24.     Error("test Error %d %s /n", 1, "hell");      
  25.     return 0;  
  26. }  

输出结果:

test printf 1 hell
err:test Error 1 hell
Press any key to continue

原创粉丝点击