I need to form a string, inside each iteration of the loop, which contains the loop index i:
for(i=0;i<100;i++) {
// Shown in java-like code which I need working in c!
String prefix = "pre_";
String suffix = "_suff";
// This is the string I need formed:
// e.g. "pre_3_suff"
String result = prefix + i + suffix;
}
I tried using various combinations of strcat and itoa with no luck.
Strings are hard work in C.
The
12is enough bytes to store the text"pre_", the text"_suff", a string of up to two characters ("99") and the NULL terminator that goes on the end of C string buffers.This will tell you how to use
snprintf, but I suggest a good C book!