【发布时间】:2011-01-05 09:06:59
【问题描述】:
我正在尝试编写一个函数,允许我在 C 中写入控制台和文件。
我有以下代码,但我意识到它不允许我附加参数(如 printf)。
#include <stdio.h>
int footprint (FILE *outfile, char inarray[]) {
printf("%s", inarray[]);
fprintf(outfile, "%s", inarray[]);
}
int main (int argc, char *argv[]) {
FILE *outfile;
char *mode = "a+";
char outputFilename[] = "/tmp/footprint.log";
outfile = fopen(outputFilename, mode);
char bigfoot[] = "It Smells!\n";
int howbad = 10;
footprint(outfile, "\n--------\n");
/* then i realized that i can't send the arguments to fn:footprints */
footprint(outfile, "%s %i",bigfoot, howbad); /* error here! I can't send bigfoot and howbad*/
return 0;
}
我被困在这里了。有小费吗?对于我要发送给函数的参数:footprints,它将由字符串、字符和整数组成。
还有其他 printf 或 fprintf fns 我可以尝试创建包装器吗?
谢谢,希望听到你们的回应。
【问题讨论】: