I am playing with printf and the idea of writing my_printf (...) which calls normal printf and sprintf Which sends the result to a special event. (I was thinking about Sprintoff because he behaves like most printfrops on most platforms).
My idea was to write a small macro:
#define my_printf (x, y ...) do {printf (x, ## y); \ Char * Data = Molec (Stellon (x) * Volume (four)); \ Sprintf (data, x, ## y); \ Other_print (data); \ Free (data);} while (0)
but since the sprintf can increase the string in size larger than x, this method breaks almost directly.
And to add only one number, it is believed to be the wrong way to attack the problem, since then I will only take the problem in future and one day when I should print a bigger expression ...
Is there a better idea about the attack on this problem? Or how do I know how big the result of Sprint will be?
Thanks Johan
UPDATE: I forgot how many printf prints it, and since I already have a macro Calling printf This is a very easy thing that adds the int save the number.
#define buf_printf (x, y ...) do {int len = printf (x, ## y); \ Char * Data = Molok ((lane + 1) * size (four)); \ Sprintf (data, x, ## y); \ Other_print (data); \ Free (data);} while (0)
update: I was thinking about this and maybe using a normal function that looks very good Given is a good idea that there is a v-version of different print functions (vprintf, vsprintf and vsnprintf). Thanks for pointing to Thanks.
) Create a function with the same prototype and use the Warga functions to pass the data to the sprint to populate the desired buffer, and pass the printf ("% s") before returning the buffer.
There was a limit of 4K on very low level of printf () call for initial implementation, but I choose more than that. You probably only need to set an upper limit and stick it.
We had to write data to handle / dev / null using a transfiss printf () used in a logging system. Since printf () returns the number of letters written, we used it to allocate a buffer. But it was not very efficient because it included calling a printf () -type function twice.
Comments
Post a Comment