I wrote a perfectly functional recover.c
program yesterday.
But I can't get the file naming right. How can I add leading zeroes to the file name so the name is 000
instead of just 0
?
I wrote a perfectly functional recover.c
program yesterday.
But I can't get the file naming right. How can I add leading zeroes to the file name so the name is 000
instead of just 0
?
To print 000 you have to specify the format in the place holder.
for printing should be something like this:
printf("%03d", 0);
but to create a file with the name 000.jpg i think you need to use the function sprintf() wich can convert an integer to a string and then use this string to create the file.
sprintf(filename, "%03d.jpg", jpg_counter);
In this case the fist argument, filename, is where the resulting string is stored, you need to declare this string first. If the variable jpg_counter is 0 the resulting string in this case is filename = "000.jpg" the second argument is what you want to convert to a string. the third is tha variable you want to use for the placeholder.