谁能帮忙看下C supports functions that take a variable number of ar
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/17 17:57:20
谁能帮忙看下
C supports functions that take a variable number of arguments.
The va_* family of macros,defined in the standard header file ,provide
a portable way for a function to examine its arguments.Read the man pages for
stdarg(3) to learn how these work.
A common use of variable arguments is to create printf-like functions.Create a
function ’write to log,’ which is described below:
#include
#include
int loglevel;
/* If _loglevel is >= loglevel,act as if printf(format,...)
* had been called,passing all received arguments.
* Return the number of characters printed.
*/
int write_to_log(int _loglevel,const char *format,...)
{
#include "log-solution.c"
}
int
main()
{
loglevel = 2;
write_to_log(3,"Log works like printf:%s %d %c\n","a string",42,’x’);
write_to_log(1,"This should not appear","a string",42,’x’);
return 0;
那个log-solution.c应该怎么写?
C supports functions that take a variable number of arguments.
The va_* family of macros,defined in the standard header file ,provide
a portable way for a function to examine its arguments.Read the man pages for
stdarg(3) to learn how these work.
A common use of variable arguments is to create printf-like functions.Create a
function ’write to log,’ which is described below:
#include
#include
int loglevel;
/* If _loglevel is >= loglevel,act as if printf(format,...)
* had been called,passing all received arguments.
* Return the number of characters printed.
*/
int write_to_log(int _loglevel,const char *format,...)
{
#include "log-solution.c"
}
int
main()
{
loglevel = 2;
write_to_log(3,"Log works like printf:%s %d %c\n","a string",42,’x’);
write_to_log(1,"This should not appear","a string",42,’x’);
return 0;
那个log-solution.c应该怎么写?
靠,我前段时间还写了一个呢.给你参考下.
#include "MyLog.h"
#ifdef ANDROID
//nothing to do.
#else
#include
#include
void _info(const char *fmt ...)
{
va_list args;
va_start (args, fmt);
vfprintf (stderr, fmt, args);
va_end(args);
}
void _warning(const char *fmt ...)
{
va_list args;
va_start (args, fmt);
vfprintf (stderr, fmt, args);
va_end(args);
}
void _debug(const char *fmt ...)
{
va_list args;
va_start (args, fmt);
vfprintf (stderr, fmt, args);
va_end(args);
}
void _error(const char *fmt ...)
{
va_list args;
va_start (args, fmt);
vfprintf (stderr, fmt, args);
va_end(args);
}
#endif
#include "MyLog.h"
#ifdef ANDROID
//nothing to do.
#else
#include
#include
void _info(const char *fmt ...)
{
va_list args;
va_start (args, fmt);
vfprintf (stderr, fmt, args);
va_end(args);
}
void _warning(const char *fmt ...)
{
va_list args;
va_start (args, fmt);
vfprintf (stderr, fmt, args);
va_end(args);
}
void _debug(const char *fmt ...)
{
va_list args;
va_start (args, fmt);
vfprintf (stderr, fmt, args);
va_end(args);
}
void _error(const char *fmt ...)
{
va_list args;
va_start (args, fmt);
vfprintf (stderr, fmt, args);
va_end(args);
}
#endif
谁能帮忙看下C supports functions that take a variable number of ar
the number of the classes in our school ___12 A.be B.is C.ar
Destiny take a hand谁能帮忙翻译下
英语翻译Overview of subordinate clausesWhen a number of ideas ar
请帮忙翻译一段英文It was a real pain. A pain that supports your happi
帮忙英语短语区别下.a number of \a group of \a lot of\ a little of...等
The number of triples (a,b,c) of positive integers such that
谁能帮忙翻译下Scientists say there are seven kinds of food that peo
A number of students____nervous before they take any kind of
有几道题,帮忙看下!1.-Which of the three ways shall I take to the vil
英语翻译A variable is anything that can vary,i.e.changed or be c
英语翻译1.The high number of attacks could be a result of the ar