Remove C99-only feature (declaring variable inside for loop initialiser)
Avoid buffer overflows (sprintf -> snprintf & strcpy -> strncpy)