For example
sprintf(pos,"%f ",cl.snap.ps.origin[0]); //don't start with strcat
sprintf(tmp,"%f ",cl.snap.ps.origin[1]);strcat(pos, tmp);
fine.
with
sprintf(tmp,"%f ",cl.snap.ps.origin[0]);strcat(pos, tmp);
sprintf(tmp,"%f ",cl.snap.ps.origin[1]);strcat(pos, tmp);
not fine.
The
strcat()function expects that the destination argument already contains a properly null-terminated string. In your case, it sounds likeposcontains some junk that looks like a null-terminated string, but isn’t what you expect.strcat()is dutifully appending on to the end of that junk.One way to fix this is to initialise
posbefore your code: