-1
我试图对一些没有记录的外部硬件进行一些调查。
对于这个我正在使用的可变参数在C.这是我自己的小记录器是我的代码:如何使用可变参数写入WinCE小型记录器
void write(const char* msg, ...)
{
va_list args;
va_start(args, msg);
FILE* file = fopen("/network/cewin/loggerfile.txt", "a");
if(file != NULL)
{
vfprintf(file, msg, args);
fputc('\n', file);
fclose(file);
va_end(args);
}
}
首先,我测试在Windows 7的代码,没有问题,但在WinCE的不打印含参数的线。
下面是一个例子:
write("Hello World") - Works on Win 7 and WinCE
write("Hello %s", "World") - Works on Win7, not on WinCE
write("Hello %i", 5) - Works on Win7, not on WinCE
我试图理解为什么最后两行是在Win7的工作,但不能在WinCE的。也许我需要使用别的东西比vfprintf
?
由于HW,我无法检查方法的返回值。
如果['fopen'(HTTPS://linux.die .net/man/3/fopen)失败,那么你应该检查['errno'](https://linux.die.net/man/3/errno)以找出问题所在...... –
我不' t认为它失败了,因为如果我打印一个简单的字符串:“Hello world”,它在WinCE上工作,文件被创建,但是如果我打印这个:(“Hello%s”,“World”),它不会加工。 – Kobe
@MichaelWalz:它可以,它适用于简单的字符串 – Kobe