diff options
Diffstat (limited to 'man3/stdarg.3')
| -rw-r--r-- | man3/stdarg.3 | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/man3/stdarg.3 b/man3/stdarg.3 index 465aeb4302..dbbbc012d6 100644 --- a/man3/stdarg.3 +++ b/man3/stdarg.3 @@ -201,46 +201,6 @@ Some systems that do not supply have .B __va_copy instead, since that was the name used in the draft proposal. -.SH EXAMPLE -The function -.I foo -takes a string of format characters and prints out the argument associated -with each format character based on the type. -.RS -.nf - -#include <stdio.h> -#include <stdarg.h> - -void -foo(char *fmt, ...) -{ - va_list ap; - int d; - char c, *s; - - va_start(ap, fmt); - while (*fmt) - switch(*fmt++) { - case 's': /* string */ - s = va_arg(ap, char *); - printf("string %s\en", s); - break; - case 'd': /* int */ - d = va_arg(ap, int); - printf("int %d\en", d); - break; - case 'c': /* char */ - /* need a cast here since va_arg only - takes fully promoted types */ - c = (char) va_arg(ap, int); - printf("char %c\en", c); - break; - } - va_end(ap); -} -.fi -.RE .SH "CONFORMING TO" The .BR va_start (), @@ -303,3 +263,43 @@ pass all of their arguments on to a function that takes a .B va_list argument, such as .BR vfprintf (3). +.SH EXAMPLE +The function +.I foo +takes a string of format characters and prints out the argument associated +with each format character based on the type. +.RS +.nf + +#include <stdio.h> +#include <stdarg.h> + +void +foo(char *fmt, ...) +{ + va_list ap; + int d; + char c, *s; + + va_start(ap, fmt); + while (*fmt) + switch(*fmt++) { + case 's': /* string */ + s = va_arg(ap, char *); + printf("string %s\en", s); + break; + case 'd': /* int */ + d = va_arg(ap, int); + printf("int %d\en", d); + break; + case 'c': /* char */ + /* need a cast here since va_arg only + takes fully promoted types */ + c = (char) va_arg(ap, int); + printf("char %c\en", c); + break; + } + va_end(ap); +} +.fi +.RE |
