The solution I gave you works for all 7 digit number.
char filename[10];
sprintf(filename,"%07d", 1);
sprintf(filename,"%07d", 10);
sprintf(filename,"%07d", 100);
sprintf(filename,"%07d", 1000);
sprintf(filename,"%07d", 10000);
sprintf(filename,"%07d", 100000);
sprintf(filename,"%07d", 100000);
-Saurabh