My code works, but dont know why it is char filename. Why 7? Why not another number?Thanks.
// create filename char filename; sprintf(filename, "%03i.jpg", jpg_number);
[snip out unneeded code]
CS50 Stack Exchange is a question and answer site for students of Harvard University's CS50. It only takes a minute to sign up.Sign up to join this community
char filename. You need three characters for the digits, four for the
.jpg, and one for the null terminator marking the string end.
It still works with 7 as probably the next byte in memory is unused (variables might be placed at memory addresses divisible by 2, 4, or 8, depending on type, as those can be faster to access). Otherwise, you'd overwrite a byte of another variable with the null terminator (a byte of zero).