I would like to define two functions: fdump and sdump, to upload the structure to a file or to a buffer using fprintf and sprintf in each case.
Is there a way to define them without repeating the code in two functions? One solution could be to define sdump and then fdump on it, ei:
void fdump(FILE* f, struct mystruct* param) { char buffer[MAX]; sdump(buffer, MAX, param); fprint(f, "%s", buffer); }
But this is a dissolution of waste and an intermediate buffer. Although perhaps fprintf does the same. Another solution might be to use preprocessing macros, but it looks rather complicated. Any ideas please?
Thanks in advance
source share