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
3answers
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 ...
8
votes
1answer
902 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 ...
7
votes
2answers
419 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 ...
5
votes
1answer
690 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) { ...
5
votes
3answers
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 ...
4
votes
1answer
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 : ...
4
votes
4answers
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 ...
4
votes
2answers
1k 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] ...
4
votes
3answers
4k 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 ...
4
votes
1answer
577 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 ...
4
votes
2answers
293 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....
3
votes
1answer
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: (...
3
votes
2answers
1k 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 ...
3
votes
2answers
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, ...
3
votes
1answer
450 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 ...
3
votes
1answer
950 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(...
3
votes
1answer
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 ...
3
votes
1answer
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. ...
3
votes
1answer
1k 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 ...
3
votes
1answer
624 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/...
2
votes
1answer
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 ...
2
votes
3answers
833 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 ...
2
votes
1answer
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 ...
2
votes
1answer
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 ...
2
votes
2answers
298 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.imgur.com/Ovs2Xv8.png. I can't really find what's wrong in my ...
2
votes
1answer
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 ...
2
votes
1answer
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 ...
2
votes
2answers
505 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? // ...
2
votes
2answers
700 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 [-...
2
votes
1answer
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 | ...
2
votes
2answers
2k 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 ...
2
votes
1answer
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 ...
2
votes
3answers
797 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 ...
2
votes
1answer
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 ...
2
votes
1answer
564 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, ...
2
votes
1answer
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 ...
2
votes
1answer
843 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(...
2
votes
2answers
174 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 ...
2
votes
1answer
842 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 ...
2
votes
1answer
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 ...
2
votes
1answer
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 ...
2
votes
2answers
318 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 ...
2
votes
1answer
70 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]) { ...
2
votes
3answers
137 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 (...
2
votes
2answers
217 views

PSET 4 Reflect help

I am not sure why I am having issues with my code. I know I can store the rgb values for the left pixels in 3 temporary variables then assign the right values to the left and the temp values to the ...
2
votes
1answer
26 views

Using * and & both works

SPOILER ALERT THIS CODE ALREADY WORKS SO DON'T LOOK IF YOU'RE STILL SOLVING I'm just wondering why my code still works even if I change fwrite(buffer, 512,1, img); to fwrite(&buffer, 512,1, img); ...
2
votes
1answer
148 views

Recover makes file for JPG but gives strange output

I've been staring at this for days and can't seem to find what's wrong. My code compiles, makes a file for the JPG's found, only doesn't show the JPG's but a weird screen full of symbols in white and ...
2
votes
1answer
138 views

pset4: Order in structs and "word-aligning" by clang

I was just reading the pset4 text and can't get my head around this part: As this figure suggests, order does matter when it comes to structs' members. Byte 57 is rgbtBlue (and not, say, rgbtRed),...
2
votes
1answer
545 views

pset4 resize doesn't resize

I have been looking for answers here but wasn't able to make the code work, so I am hoping someone will be able to help with this question. I have been working on pset4 resize for several days now and ...
2
votes
1answer
266 views

Comparing jpg-signatures with fread-buffer; Can't find something

Using the if condition I am trying to compare the buffer with the given jpg signatures, but I never find something. In GDB I just see the while looping, but never entering the if condition. What have ...

1
2 3 4 5
35