Videos
The value 6778986 gives 0x0067706A in hexadecimal, which correspond to the last 3 ASCII characters and the null terminator ("jpg") of what should have been in the picture string.
This indicates that you defined picture just before pic_num, and only 4 bytes large. I'm guessing you defined it as :
char picture[4];
You need to properly size the string to hold at least 8 characters (but potentially more depending on how large the pic_num value can get), so what gets written into it by sprintf doesn't overflow into pic_num. For example :
char picture[16];
For more info on what sprintf does, refer to this reference eg. : http://en.cppreference.com/w/c/io/fprintf
sprintf writes the results to a character string buffer. So it is like printf but instead of printing to stdout it stores result in a buffer
int sprintf( char* buffer, const char* format, ... );
The size of the buffer should be large enough to contain the entire resulting string which is characters + terminating null at the end. You can use a snprintf as a safer version.
You have got 6778986 because this resulted from taking pASCII values of characters "jpg" (with terminating '\0'), the `0x0067706A'
'\0' 'g' 'p' 'j'
0x00 67 70 6A
what tells us that most probably your picture is incorrectly declared as
char picture[4];
and thus has not enough space for 8 characters string "%03d.jpg" (+ '\0').
You should declare buffer as
char picture[8]; // space for at least 7 characters + '\0'