Skip to main content

Questions tagged [pset4]

The standard edition of Problem Set 4 will move beyond C programming language basics, testing your knowledge of pointers, memory management, file i/o and structs.

Filter by
Sorted by
Tagged with
10 votes
3 answers
1k views

pset4 speller - can't pass valgrind test - 32 bytes still reachable

Can't pass valgrind test on pset4 speller (hashtable). The speller works perfectly but, I'm getting this message from valgrind: ==3911== ==3911== HEAP SUMMARY: ==3911== in use at exit: 32 bytes ...
agraffe's user avatar
  • 101
8 votes
1 answer
948 views

Help me write sexier code : ) counters as pointers, buffering files, feof, sprintf [pset4.recover]

I have completed the pset, and am happy with my code and how it works. But had some design questions so that I know for future programs what and why to use. I understand that it does not really ...
freshsisyphus's user avatar
7 votes
2 answers
425 views

getType() causing a seg fault when called on object as returned by detectcollision?

This one is driving me nuts! Why would I get a seg fault when calling getType() on 'object' as returned by detectCollision()? gdb revels this is where the memory error is happening but as far as I can ...
tidymonkey81's user avatar
6 votes
2 answers
2k views

Understanding how memory is allocated in driver code PSET 4, Filter (Less Comfortable)?

What does the following line do, step by step (filter.c L:78) RGBTRIPLE(*image)[width] = calloc(height, width * sizeof(RGBTRIPLE)); I am most confused by the syntax of RGBTRIPLE(*image)[width] ...
drl's user avatar
  • 81
5 votes
1 answer
695 views

Is something wrong with getType(object)?

For pset4, in this code(in main, to check collision of ball and anything else): GObject object = detectCollision(window, ball); if (strcmp(getType(object), "GRect") == 0) { ...
Confused Guy's user avatar
5 votes
3 answers
6k views

Pset4 Whodunit: Any way to enhance the image?

So I removed all the 'red noise' from the image but I don't recognize the person. My question is : Do I have to enhance the colors any more or do I need to just guess the identity of the person ...
Uzair Ahmed's user avatar
4 votes
1 answer
2k views

PSET4 speller can't use strcasecmp() function

I'm working on the check() part of dictionary.c. I wanted to use strcasecmp() to compare the text word and the word in my dictionary. Nevertheless, it doesn't work. It keeps pop up the error : ...
Jn Wu's user avatar
  • 55
4 votes
3 answers
6k views

Pset4: What is padding exactly?

I am working with BMP file. In copy.c we have this code // determine padding for scanlines int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; What is padding exactly in BMP file ? do I ...
Eli Tuan Nguyen's user avatar
4 votes
4 answers
1k views

Running breakout on Mac OS X

There's a similar question about running breakout on Linux variants: Can't run Breakout outside of appliance My question is specifically about compiling breakout (and hence SPL) on Mac OS X. So ...
Luke Van In's user avatar
  • 2,655
4 votes
1 answer
598 views

what is fseek() exactly doing?

I'm stuck since a while in the 'resize' task. Don't fully get my head around the padding. // read scanline pixel/pixel from infile // write pixels to outfile // skip padding // add padding back ...
gado007's user avatar
  • 59
4 votes
1 answer
2k views

pset 4 : filter - Could not open .bmp file

I have a trivial question. Starting the pset with freshly downloaded and unchanged code and trying to pass a file with ./filter -g yard.bmp out.bmp yields : Could not open yard.bmp. I wrote a simple ...
Wyatt McLaren's user avatar
4 votes
2 answers
296 views

PSET4 resize more: Check50 indicates 3 errors (1x1px to 3x3 - 5x5 px)

I'm now doing the pset4 resize more version as I have already done the 'less version' with successfull check50. For my 'more version' check50 indicates 3 errors although visually my outputs look good....
Poki's user avatar
  • 41
3 votes
1 answer
1k views

pset4: resize.c - why is biWidth written as bi.biWidth

I am working on resize.c, and I was wondering why when you set the new dimensions for the bitmap, the width and height in the code are written as bi.biWidth and bi.biHeight. i.e. why do you write: (...
clouding_980's user avatar
3 votes
2 answers
2k views

Why abs(bi.biHeight)?

I have written pset4's resize.c and it took me a while to find the bug in my code. All I want to ask is what is the difference between bi.biHeight and abs(bi.biHeight)? With bi.biHeight some cases ...
Mustaghees's user avatar
3 votes
2 answers
504 views

Bricks aren't disappearing when hit with the ball

I wrote the following code (within the while loop) but my bricks aren't disappearing. My ball just hits the bricks and bounces off. What am I missing here? GObject object = detectCollision(window, ...
dottified's user avatar
3 votes
1 answer
458 views

Bricks are not available to the detectCollision function

My detectCollision function detects collisions between ball and paddle, but not between ball and bricks. Bricks 'exist' in 'window' but they don't exist in main(). I thought detectCollision might ...
Shaun Brophy's user avatar
3 votes
1 answer
970 views

pset4 resize.c negation of 12 cannot be represented in type unsigned long

BITMAPFILEHEADER new_bf; BITMAPINFOHEADER new_bi; new_bf = bf; new_bi = bi; new_bi.biHeight = bi.biHeight*factor; new_bi.biWidth = bi.biWidth*factor; int padding = (4 - (bi.biWidth * sizeof(...
Vincent Tang's user avatar
3 votes
1 answer
2k views

Questions regarding pset4 Blur filter (less comfortable)

After tinkering for a while with why my filter didn't work, I finally succeded with the following code: // Blur image void blur(int height, int width, RGBTRIPLE image[height][width]) { //make copy ...
Miloš Nenadić's user avatar
3 votes
1 answer
966 views

helpers.c not compiling for filter

I am doing filter less comfortable in pset4. My filter file compiles fine, but helpers.c gives the following error : clang-7: error: linker command failed with exit code 1 (use -v to see invocation) ...
Musical_Ant's user avatar
3 votes
1 answer
1k views

:( recovers 049.jpg correctly recovered image does not match

I have problem with pset4/recover. I recover all images and can see last image when I click on it but when I run check50 it returns with error: :( recovers 049.jpg correctly recovered image does not ...
Ivan Stimac's user avatar
3 votes
1 answer
1k views

PSET 4: Why is padding required?

I am currently going through the PSET 4 sheet and have just read up to the part where it is being explained that if the number of bytes in each scan line is not a multiple of 4 then it is padded out. ...
gowerc's user avatar
  • 131
3 votes
1 answer
639 views

pset4 debugger stopping

In the copy.c program, when my debugger reaches line 37 FILE* outptr = fopen(outfile, "w"); I can step into it twice, but then the debugger immediatley exits with this prompt Compiling /home/ubuntu/...
user10805's user avatar
2 votes
1 answer
4k views

Pset4 resize.c - bfsize & bisizeimage formulas

First of all thanks for your time. Taking cs50 through edX - struggling as all alone here and videos / lectures are burnt out for information - need real people! Online cs50 really does assume a lot ...
KrisValentine's user avatar
2 votes
3 answers
842 views

Collision of ball with other objects

I don't understand what I actually have to do for the collision of ball with other objects. I am at the state where ball and paddle are just moving but collision is not yet defined. What should I do ...
user1199's user avatar
2 votes
1 answer
3k views

How does “RGBTRIPLE triple;” know whitch pixel to store?

I'm currently working on the cs50 pset4. My question is pretty straight forward: How does the line (marked with caps lock comment) "RGBTRIPLE triple;" knows whicht pixel currently to store? I get the ...
C4zZ's user avatar
  • 37
2 votes
1 answer
1k views

pset4 recover I'm confused with fread

I'm pretty confused with recover. I've seen in previous posts that it is wrong to use feof , but the problem is that when I use fread the images won't show. However, when I use feof I can see all ...
Belen's user avatar
  • 87
2 votes
1 answer
2k views

pset4 filter: reflect the image reflect half only

if I remove this line (*a = temp2) the left image only reflects and if I remove this line (*b = temp ) the right image only reflects but if I write both the image return into the original one no ...
Mahmoud Mohamed's user avatar
2 votes
2 answers
323 views

pset4 recover: recovered images seems to still be corrupted

My code compiles and runs without any errors. Images are generated, but the images are incomplete, here's an example of 000.jpg: https://i.sstatic.net/gCTju.png. I can't really find what's wrong in my ...
Birkhoff Lee's user avatar
2 votes
2 answers
664 views

Can't seem to wrap my head around what the Bitwise AND operator does in Pset4 vs. && AND operator

I just watched the Recover video and I saw them mention bitwise arithmetic, but I am not exactly sure what that means nor what it does. I saw another forum post explain it but that also didn't really ...
Ruben Alias's user avatar
2 votes
1 answer
1k views

pset4 resize - fseek help (I think)

I'm on the verge of giving up. I've been stuck on this problem for weeks. I managed the headers, and I think I set up the loops right to write the pixels correctly. I just can't wrap my head around ...
Bubi's user avatar
  • 88
2 votes
1 answer
2k views

cs50 pset 4 Recover - I get 50 blank images of different sizes

I cannot figure out where in heck I've gone wrong with this program. It outputs 50 files, numbered correctly and with different sizes. However, they are all blank. When I run "head -q -c4 *.jpg | ...
Timothy Chasteen's user avatar
2 votes
2 answers
523 views

Why Do I Get a Segmentation Fault When Trying to Move the Paddle?

I am trying to get the paddle moving with the mouse but I keep getting the same error message : "Segmentation Fault (Core Dumped)". This is my function, which is very simple. Any suggestions? // ...
Loic's user avatar
  • 25
2 votes
2 answers
2k views

.wav file incorrectly reversing

Not able to pass final test for check50, however the only information I have is "file is not reversed as specified". I assume this means that I failed to properly reverse the data in the ...
Danyal Ahmed's user avatar
2 votes
2 answers
6k views

Pset4 filter edges issue

I'm trying to figure why my code doesn't work for detecting edges. Even though it produces a result, it is too white. Any suggestions? // Detect edges void edges(int height, int width, RGBTRIPLE ...
Marianna's user avatar
2 votes
2 answers
747 views

Pset4 recover, comparing hex in if statements

I'm trying to solve "recover" but, I'm unable to compare my if statements. This is my error message: error: comparison of constant 224 with expression of type 'char' is always false [-...
olafironfoot's user avatar
2 votes
1 answer
1k views

Recover where to start from?

I finished resize after spending days on it and took a week break, today I read what recover is and after reading it I am having that feeling as to what to do where to start from? Have spend like ours ...
Furrukh Jamal's user avatar
2 votes
2 answers
3k views

segmentation fault, probably because of sprintf

for my recover.c i have trouble changing the filenames. I get a segmentation fault probably because of incorrect usage of sprintf. Code looks sort of like this: { // pseudocode for testing ...
Mihaly's user avatar
  • 151
2 votes
1 answer
2k views

Resize's Padding Issue

My resize for pset4 finally worked and I can resize the small.bmp (that green square) properly. however it doesn't work for all the check50 requirements(except for compiling and running) and i don't ...
Florence Wu's user avatar
2 votes
1 answer
385 views

My code works, but dont know why it is char filename[7]. Why 7? Why not another number?

My code works, but dont know why it is char filename[7]. Why 7? Why not another number?Thanks. // create filename char filename[7]; sprintf(filename, "%03i.jpg", ...
stephen Ong's user avatar
2 votes
3 answers
846 views

jpg's fourth byte

Reviewing my code after successfully recovering the images in pset4, I see a part I just copied (from Zamyla's video) without understanding. Mainly, the following: (block[3] & 0xf0) == 0xe0 I ...
snoram's user avatar
  • 150
2 votes
1 answer
570 views

How do the headers in copy.c update on pset4?

I don't really understand the following code in copy.c: // write outfile's BITMAPFILEHEADER fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr); // write outfile's BITMAPINFOHEADER fwrite(&bi, ...
SwiftSilent's user avatar
2 votes
1 answer
89 views

Pset4 recover: Form of bytes when they're read in?

I am stuck on figuring out what form the bytes are in when they're read? I created a buffer of type char and I get one result when I read the bytes in. Then I created a buffer of type int and I get a ...
Jón Árnason's user avatar
2 votes
1 answer
868 views

Segmentation fault (core dumped) in the updateScoreboard function of pset4

I am having a problem with the updateScoreboard function in pset4. Whenever I call it I get a Segmentation fault (core dumped) error. My code is the following: if(object!=NULL && strcmp(...
Kheyreddine Hadri's user avatar
2 votes
2 answers
177 views

Resize is not passing check50, but still properly scaling larger images

I can get smiley.bmp and large.bmp to scale properly, but not small.bmp, where the former is 3x3 and the latter two are larger (exactly how much larger I don't know) -- so I assume my program only ...
kluvin's user avatar
  • 1,223
2 votes
1 answer
927 views

How does copy.c know which RGBTRIPLE it is supposed to copy?

I don't understand how the program knows where in the infile it is. I am imagining a sort of cursor that automatically moves to the end of what has been read by fread (is this correct?). How does ...
noggy's user avatar
  • 53
2 votes
1 answer
1k views

resize in pset4 - can't figure it out

I have been stuck on the resize pset for a few days now. I have looked at all questions on here and reddit but just can't figure it out. When I do the peek, the headers seem consistent with the staff ...
Breninio's user avatar
2 votes
1 answer
1k views

pset4 : How does the xxd command work?

Specifically, could someone explain what the flags used with the commands are? In the pset4 specs at one point it is mentioned that they use a different value for -c depending upon the number of ...
sharvari murthy's user avatar
2 votes
2 answers
476 views

Possible error in solution video of pset4 lab 'volume' within fread() function of header

I think there is an error in the solution video of pset4 lab called 'volume' within the fread() function of the header (of the wav file). I think they swapped 'header_size and '1' - so they swapped ...
c_dinosaur's user avatar
2 votes
1 answer
85 views

pset4 - filter program,can't figure out what exactly is the problem with blur!

Can't figure out what the problem with this code is. It seems to be working correctly for corners, but for nothing else. Please help! void blur(int height, int width, RGBTRIPLE image[height][width]) { ...
Lakshya Dugar's user avatar
2 votes
3 answers
211 views

pset4 filter grey scale error

when I try to test the code I get an infinite loop of errors: UndefinedBehaviorSanitizer:DEADLYSIGNAL what am i missing ??? void grayscale(int height, int width, RGBTRIPLE image[height][width]) { for (...
andream's user avatar
  • 109

1
2 3 4 5
37