This has me confused.
In the following code, I create an array of characters initialized at size 7. The array needs to store at least 6 characters, so I've made it large enough to do that (I think?). Then with the next line of code I put the string "000.jpg" into that array. Then I write data into a file with that string as its name. The program works fine and all files are named correctly.
//create a string for the name of the new jpg char filename; //name the new jpg according to the current file number sprintf(filename, "%03i.jpg", file_number); //open new jpg file photo = fopen(filename, "w"); //write first bloc of new jpg fwrite(buffer, sizeof(unsigned char), 512, photo);
But then I changed this line to:
//create a string for the name of the new jpg char filename;
and the files are still named correctly. So my question is why?
If an array is a fixed size, why can I store then entire file name in it if it's more than 3 characters?
I'm happy to share the rest of the program if it helps. thanks!