c语言:printf系列的函数

/**
*----------------------------stdio.h---------------------------------------
* int printf(const char *format, ...)
* int fprintf(FILE *stream, const char *format, ...)
* int sprintf(char *str, const char *format, ...)
* int snprintf(char *str, size_t size, const char *format, ...)
*
* --------------------------stdarg.h---------------------------------------
* int vprintf(const char *format, va_list ap)
* int vfprintf(FILE *stream, const char *format, va_list ap)
* int vsprintf(char *str, const char *format, va_list ap)
* int vsnprintf(char *str, size_t size, const char *format, va_list ap)
*/
#include <stdio.h>
#include <stdarg.h> int _vprintf(const char *fmt, ...){
int ret;
va_list ap;
va_start(ap, fmt);
ret = vprintf(fmt, ap);
va_end(ap);
return ret;
} int _vfprintf(const char *fmt, ...){
int ret;
va_list ap;
va_start(ap, fmt);
ret = vfprintf(stdout, fmt, ap);
va_end(ap);
return ret;
} int _vsprintf(const char *fmt, ...){
char buf[];
int ret;
va_list ap;
va_start(ap, fmt);
ret = vsprintf(buf, fmt, ap);
printf("%s", buf);
va_end(ap);
return ret;
} int _vsnprintf(const char *fmt, ...){
char buf[];
int ret;
va_list ap;
va_start(ap, fmt);
ret = vsnprintf(buf, sizeof(buf),fmt, ap);
printf("%s", buf);
va_end(ap);
return ret;
} int main(){
int ret;
char buf[]; //printf
ret = printf("%d---%s\n", , "printf");
printf("ret = %d\n", ret); //fprintf
ret = fprintf(stdout, "%d---%s", , "fprintf");
printf("ret = %d\n", ret); //sprintf
ret = sprintf(buf, "%d---%s", , "sprintf");
printf("%s, ret = %d\n", buf, ret); //snprintf
ret = snprintf(buf, sizeof(buf), "%d---%s", , "snprintf");
printf("%s, ret = %d\n", buf, ret); //vprintf
ret = _vprintf("%d---%s\n", , "vprintf");
printf("ret = %d\n", ret); //vfprintf
ret = _vfprintf("%d---%s\n", , "vfprintf");
printf("ret = %d\n", ret); //vsprintf
ret = _vsprintf("%d---%s\n", , "vsprintf");
printf("ret = %d\n", ret); //vsnprintf
ret = _vsnprintf("%d---%s\n", , "vsnprintf");
printf("ret = %d\n", ret);
}
上一篇:基于opencv图片切割


下一篇:unbuntu下的root 用户和 sudo 命令