I was wondering if someone could help explain why an while loop cannot be used for the copying of the header for the .wav file. I originally used a while loop like the one from the cp.c in the lecture. It wasn't working so I looked up some resources online and saw that someone had done this without the while loop. I tried it without the while loop and it worked. I'm just not really clear as to why this is. I'm pretty new to computer science and coding in general so I'm just trying to figure this all out. Thank you in advance for the help!

1 Answer 1


I can't think of a technical reason that a while loop can't be used to write the header. Pseudo code something like

  • Read the input file 2 bytes at a time until end of file (while loop)
  • If num reads less than half the header size, write bytes to output file
  • otherwise, do the math and write bytes to ouptut file.

This assumes an even header size; it "feels" less efficient. And full disclosure, I haven't tested the pseudo code. If you want specific input on why it didn't work, you'd have to post the code.

  • Thank you! I don't have the original code anymore since I've changed it to one that works but I'll make sure to post it next time. I'm guessing I probably made a mistake with the while loop, possibly misreading the number of bytes from the input file. Nov 17, 2021 at 0:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .