I don't want an explicit solution, but some clarity in my understanding.

1) The buffer. Is using a char or int buffer a hack approach? I thought about typedef byte or block but what's the conventional idea? Furthermore: I really want my loop to be "while fread buffer" but then I have to declare my buffer outside of the loop. We haven't learned realloc yet so the solution I came up with was simply declaring the buffer outside the loop and letting the loop continuously overwriting it... is this what results in buffer overflow (aka a bad solution)?

2) I'm really stumped on the following :

if (we found a jpg) {make a new file} ... fwrite(overflowing buffer, 512, 1, Oh wait how do I write to this file, stuck in the 'if' loop's scope?)

  • So I figured it out, and got all my smileys faces :). Still, I'm wondering: I used an unsigned char * buffer and a BYTE (typedef uint8_t) buffer. Is either one more or less correct than the other? I never bothered freeing up my malloc'd buffer until the very end of the program. Again, is that incorrect? (Valgrind didn't detect memory leaks, but I just want to check with you guys). On a side note, the mooc.fi Java course left me feeling pretty confident. CS50 seems to be pummeling me.
    – Ben Wong
    Sep 13, 2018 at 7:52
  • 1
    Glad you figured it out on your own. Can you post an answer with your solution please, and then accept the answer? Otherwise this question will stay in the unanswered question pool forever. thanks.
    – Cliff B
    Sep 26, 2018 at 5:10


You must log in to answer this question.

Browse other questions tagged .