[s][v]printf anyone?
I want to know how many characters [v]printf outputs. Any suggestions how this could be achieved?
thanks
sprintf returns an integer that indicates the number of characters written to the buffer, not counting the null terminator, or negative if error.
vprintf is the same way.
-fel
Edited by - felisandria on 2/14/00 1:27:27 PM
vprintf is the same way.
-fel
Edited by - felisandria on 2/14/00 1:27:27 PM
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
I think he''s referring to the commands sprintf() and vprintf(). I''m not really sure what they return, but i figured i''d help by clearing that up.
Yes, I suddenly realized that while buzzing the other posts. I think I've been spoiled by my MFC work, I'm forgetting my C basics. *wry smile*
That, and thanks to certain forums, I see brackets and think "ooh. formatting error."
-fel
Edited by - felisandria on 2/14/00 1:30:22 PM
That, and thanks to certain forums, I see brackets and think "ooh. formatting error."
-fel
Edited by - felisandria on 2/14/00 1:30:22 PM
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
Yes, the return value of sprintf and vprintf is an int type. The following description is taken out of the help files of MS VC++
sprintf returns the number of bytes stored in buffer, not counting the terminating null character. swprintf returns the number of wide characters stored in buffer, not counting the terminating null wide character.
vprintf and vwprintf return the number of characters written, not including the terminating null character, or a negative value if an output error occurs.
B.o.t.G.
--------
Writer of the VQAtoAVI conversation utility for CC
sprintf returns the number of bytes stored in buffer, not counting the terminating null character. swprintf returns the number of wide characters stored in buffer, not counting the terminating null wide character.
vprintf and vwprintf return the number of characters written, not including the terminating null character, or a negative value if an output error occurs.
B.o.t.G.
--------
Writer of the VQAtoAVI conversation utility for CC
B.o.t.G.--------Writer of- VQAtoAVI, the conversation utility for C&C- Golden Cow, the BO2K attacher
Well, I was actually referring to all of them... But that''s not the point. What I want to know is how many characters are going to be written, not how many were written. I have to know in order to get the size of the buffer I''m writing into adjusted. (otherwise the os wouldn''t like it!)
Anyway, thanks for the quick response.
Anyway, thanks for the quick response.
Well, I suppose you can have a really big buffer to temporarily sprintf or vprintf into, find out the size of what was printed using the return value (and remembering to add space for your null terminator!), and then print to your actual buffer. Or, depending on what you are vprintf-ing or sprintf-ing, you could do a sizeof() before calling the function.
-fel
-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement