📄 subject_67092.htm
字号:
<blockquote><p>
回复者:米罗 回复日期:2003-12-30 12:33:17
<br>内容:那你去看看c语言的printf函数吧。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:林建华 回复日期:2003-12-30 13:02:49
<br>内容:<BLOCKQUOTE>引用“第4楼”所言<BR><Q>谢谢楼上的两位,不过,我实在太笨,iwill提供的那个例子我都快看睡着了,也没有看明白怎么用?</Q></BLOCKQUOTE><BR>那千万记得要把它打印出来贴在床前,以后睡不着的时候看看<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:badboy 回复日期:2003-12-31 10:09:37
<br>内容: 我看的脑袋都疼了,也没有看懂!下面这个例子我怎么没有看出和printf()函数有关啊!?? <BR><BR><BR>Example<BR><BR>/* VA.C: The program below illustrates passing a variable<BR> * number of arguments using the following macros:<BR> * va_start va_arg va_end<BR> * va_list va_dcl (UNIX only)<BR> */<BR><BR>#include <stdio.h><BR>#define ANSI /* Comment out for UNIX version */<BR>#ifdef ANSI /* ANSI compatible version */<BR>#include <stdarg.h><BR>int average( int first, ... );<BR>#else /* UNIX compatible version */<BR>#include <varargs.h><BR>int average( va_list );<BR>#endif<BR><BR>void main( void )<BR>{<BR> /* Call with 3 integers (-1 is used as terminator). */<BR> printf( "Average is: %d\n", average( 2, 3, 4, -1 ) );<BR><BR> /* Call with 4 integers. */<BR> printf( "Average is: %d\n", average( 5, 7, 9, 11, -1 ) );<BR><BR> /* Call with just -1 terminator. */<BR> printf( "Average is: %d\n", average( -1 ) );<BR>}<BR><BR>/* Returns the average of a variable list of integers. */<BR>#ifdef ANSI /* ANSI compatible version */<BR>int average( int first, ... )<BR>{<BR> int count = 0, sum = 0, i = first;<BR> va_list marker;<BR><BR> va_start( marker, first ); /* Initialize variable arguments. */<BR> while( i != -1 )<BR> {<BR> sum += i;<BR> count++;<BR> i = va_arg( marker, int);<BR> }<BR> va_end( marker ); /* Reset variable arguments. */<BR> return( sum ? (sum / count) : 0 );<BR>}<BR>#else /* UNIX compatible version must use old-style definition. */<BR>int average( va_alist )<BR>va_dcl<BR>{<BR> int i, count, sum;<BR> va_list marker;<BR><BR> va_start( marker ); /* Initialize variable arguments. */<BR> for( sum = count = 0; (i = va_arg( marker, int)) != -1; count++ )<BR> sum += i;<BR> va_end( marker ); /* Reset variable arguments. */<BR> return( sum ? (sum / count) : 0 );<BR>}<BR>#endif<BR><BR><BR>Output<BR><BR>Average is: 3<BR>Average is: 8<BR>Average is: 0<BR><BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -