I need to form a string, inside each iteration of the loop, which contains the loop index i:
i
for(i=0;i<100;i++) { // Shown in java-like cod
Look at snprintf or, if GNU extensions are OK, asprintf (which will allocate memory for you).