Fortunately, you don’t need to. You just want to use the v
variants of printf
and fprintf
that take a va_list
instead of your passing arguments directly:
void tee(FILE *f, char const *fmt, ...) {
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
va_start(ap, fmt);
vfprintf(f, fmt, ap);
va_end(ap);
}
Related Contents:
- Read/write files within a Linux kernel module
- C read file line by line
- When should I use mmap for file access?
- C fopen vs open
- Atomicity of `write(2)` to a local filesystem
- Why is fseek or fflush always required between reading and writing in the update modes?
- Reading the whole text file into a char array in C
- read comma-separated input with `scanf()`
- C write in the middle of a binary file without overwriting any existing content
- Read and write to binary files in C?
- What happens if I don’t call fclose() in a C program?
- What is the difference between read() and fread()?
- File Operations in Android NDK
- Read line from file without knowing the line length
- What is the rationale for fread/fwrite taking size and count as arguments?
- Why is the fgets function deprecated?
- Why does open() create my file with the wrong permissions?
- C function to insert text at particular location in file without over-writing the existing text
- Unable to open a file with fopen()
- Waiting until a file is available for reading with Win32
- Error “initializer element is not constant” when trying to initialize variable with const
- Map a 2D array onto a 1D array
- What are the rules of automatic stdout buffer flushing in C?
- hash function for string
- Setting variable to NULL after free
- Function pointers and address of a function
- What does the ‘array name’ mean in case of array of char pointers?
- How to split a string literal across multiple lines in C / Objective-C?
- How do I get a specific range of numbers from rand()?
- Code for printf function in C [duplicate]
- How does kernel get an executable binary file running under linux?
- scanf regex – C
- Canonical Mode Linux Serial Port
- How can I simplify this working Binary Search code in C?
- X,Y passing size for the array in C function
- C: unary minus operator behavior with unsigned operands
- How do I measure a time interval in C?
- Sharing memory between two processes (C, Windows)
- Segmentation Fault While Creating Large Arrays in C
- Weird behavior when printing array in C?
- How to use Fused Multiply-Add (FMA) instructions with SSE/AVX
- Re-opening stdout and stdin file descriptors after closing them
- Why is printf round floating point numbers up?
- Square of a number being defined using #define
- Is my fma() broken?
- Implementation of nested functions
- How to check for signed integer overflow in C without undefined behaviour?
- Operator precedence table for the C programming language
- Stabilizing the standard library qsort?
- Why do most C developers use define instead of const? [duplicate]