I have a simple gateway listener which generates a log at the screen output via printf. I would like to record it so I can insert it in a mysql table.
printf("\nPacket received!! Decoding...");
I wonder if there is any fast way to do this is C.
In case there is, could I get both outputs at the same time?
Thanks
I’m not aware of any function that does output buffering in C. But you can simulate one easily like:
now everytime you are using
printf, use asprintfas follows:and them append this string to the buffer
keep doing the
sprintffollowed bystrcatfor every message you want to buffer and once done buffer will have the buffered output.