I am trying to write a function that allows me to write to the console and file in C.
I have the following code, but I realized that it doesn't allow adding arguments (e.g. 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; }
I'm stuck here. Any tips? For the arguments I want to send the function: footprints, it will consist of strings, characters, and integers.
Are there any other printf or fprintf fns that I can try to create a wrapper?
Thanks and hope to hear your answers.
source share