This is an edit of the previous question, I was able to fix the segmentation fault following Cliff B's good hints, Got rid of the extra fread as well. But it still does not pass check50, any hints pls ?
Code : http://pastebin.com/93F0SfMY
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
The code has two serious problems. First, it is trying to write to a file that hasn't been opened. The code checks for the signature in the first block and doesn't find it. Then, the first line after the if statement's code block for opening the file, the fwrite() call tries to write to temp, which hasn't been opened yet. This is the seg fault.
Second, you have three back to back fread statements! Simply put, this is throwing away two out of every three blocks of data.
Also, there's a slight problem with the output file name creation, but I'll leave that one for you to sort out.
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)