Strings - Hard Work on C.
#include <stdio.h> int main() { int i; char buf[12]; for (i = 0; i < 100; i++) { snprintf(buf, 12, "pre_%d_suff", i); // puts string into buffer printf("%s\n", buf); // outputs so you can see it } }
There are enough bytes in 12 to store the text "pre_" , the text "_suff" , a string up to two characters long ( "99" ), and a NULL delimiter that goes at the end of the C string buffer.
This will tell you how to use snprintf , but I suggest a good C book!
Lightness Races in Orbit Mar 02 '11 at 19:09 2011-03-02 19:09
source share