char jpgname; // Correct declaration char *jpgname = "000.jpg"; // Incorrect declaration . . sprintf(jpgname,"%03i.jpg", fileNum); // Segmentation fault seemed to occur on this line if the incorrect declaration method is used
Not a vital question for this pset but I do not understand why the second method of declaration does not work in this case.
I understand the need to allocate enough memory space when declaring, and that is what I have done by assigning to char* a string value whose length should be sufficient for the subsequent sprintf function.