Hot answers tagged

4 votes
Accepted

Pset4 Resize.c Array Overstepping

After edit: For reference, here is the pseudocode from the walkthrough: for each row       for each pixel          ...
DinoCoderSaurus's user avatar
3 votes
Accepted

PSet5 Speller - program can't identify the Misspelled words

Why is it that the simplest errors are the most frustrating and then others hide it? You have two major issues to deal with, followed by a handful of minor ones. I'll point you at the majors and you ...
Cliff B's user avatar
  • 68.7k
2 votes
Accepted

pset4: File operations using fwrite(arguments)

The reason is that the third parameter is NOT the number of times to write out the contents of buffer. It's the number of ELEMENTS, the second parameter (the size of an element) to be written. For ...
Cliff B's user avatar
  • 68.7k
1 vote
Accepted

pset4 resize - can't write all the characters from infile to outfile

There is "\n" (new line) char in the end of the first raw. So there are 33 chars, while you read-write only 32.
obesman's user avatar
  • 1,139
1 vote
Accepted

Code Seems Correct but Output is garbage

When the program has opened the card.raw file and is reading into the buffer, once the program has completed one loop iteration, how does it know to read the next block of bytes and not just the ...
Yuri Laguardia's user avatar
1 vote
Accepted

Recover Pset4 - Getting 24 images

The code does two fread() calls at the top of the while loop. The data from the first fread isn't being processed, it's just being overwritten when the loop comes back around. This means that half the ...
Cliff B's user avatar
  • 68.7k
1 vote

Query on fread (or fwrite)

The most obvious difference is the return value: fread returns the number of elements read (in this case, the number of sizeof(int)'s). If all goes well, the first formulation will return 10, while ...
ronga's user avatar
  • 1,415
1 vote
Accepted

Pset4 Recover debugging help: "While loop has empty body"

Delete the semicolon at the end of the line. It marks the end of the while loop, just like a closing curly brace.
Cliff B's user avatar
  • 68.7k
1 vote
Accepted

pset4 - Recover passed check50, but want to understand the logic on fwrite or file-pointer

First, when your program reaches line 74, you already have a file open that has it's location stored in a pointer you named img. When your program goes to write to this, it does not try to reopen it ...
Robert S. Pratt's user avatar
1 vote
Accepted

Seg Fault in Writing to JPG

Look at the following code: FILE *img = fopen(filename, "r"); ... while(findJpg(ptr, buffer, blocks) == -1) { fwrite(&buffer[i], 512, 1, img); Question: How is the code going to ...
Cliff B's user avatar
  • 68.7k
1 vote

How to write a fread function

I was researching on this as well and found this page with a comprehensive answer here. sizeof(BYTE) is equivalent to 1 so the second and third "variations" are the same. Both first and second ...
Pixces's user avatar
  • 13
1 vote

CS50 PSET4 RECOVER.C SEGMENTATION FAULT PLEASE HELP!

Having a look at your code was really helpful, I was having a hard time with this problem because I cant fully understand how fread works. You keep reading rawPtr and sending it to buffer, and the ...
Jorge Guzman's user avatar
1 vote

Pset4 Recover, help with writing images correctly

I'm not getting a really clear picture of the problems you're having (no pun intended), but I'll tackle it anyways. First, you don't need to know how big the files are, just that their data will be ...
Cliff B's user avatar
  • 68.7k
1 vote

For loop vs fwrite for resize

fwrite(&triple, sizeof(RGBTRIPLE), n, outptr); This means to write n consecutive blocks of data of size sizeof(RGBTRIPLE)starting at &triple, not to write one block n times. If this answers ...
Cliff B's user avatar
  • 68.7k
1 vote
Accepted

File pointers clarification

The for loop will write n copies of the data stored at a to the file. The single fwrite will write n*sizeof(whatever) bytes starting at the address of a. If does NOT write n copies of a. The former ...
Cliff B's user avatar
  • 68.7k
1 vote
Accepted

PSET4 Recover images not showing correctly

The logic of the program has some serious flaws. While individual statements are functioning correctly, its the overall logic that isn't working. Go back and look at what the program is doing. Read ...
Cliff B's user avatar
  • 68.7k

Only top scored, non community-wiki answers of a minimum length are eligible