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
0
votes
1answer
203 views

cannot open staff's solution in the pset4 spec

how can i open the staff's solution ~cs50/pset3/breakout/breakout After i type the above into jharvard@appliance (~): ~cs50/pset3/breakout/breakout then a white window instead of the windows with ...
0
votes
1answer
56 views

week 4 walkthrough swap

void swap (int *a, int *b) { int tmp = *a; *a = *b; *b = tmp; } I want to know if int tmp = *a, "*a" means an int value, then *a = *b, both *a and *b become pointers, ...
0
votes
1answer
259 views

Why do I get Error: Could not find or load main class stanford.spl.JavaBackEnd?

This happened to me when trying to execute the window app from src4m.zip. After compiling it on 2014 Appliance CS50 (2014-22). First the spl directory was missing form the zip file. The one installed ...
1
vote
1answer
172 views

Segmentation Fault in pset4

I keep on getting a segmentation fault on the function below and have no idea why. I used GDB to find where the fault was occurring but couldn't figure out any more than that. // keep playing until ...
1
vote
2answers
184 views

Why my new ball is not moving?

while (lives > 0 && bricks > 0) { move (ball,velocity,velocity_y); if(getY(ball) > 555) { lives -= 1; remove(window,ball); pause(2000); ...
0
votes
2answers
65 views

Problems implementing initBall()

I have written the code for pset4 but I have an odd problem and I can't find the solution for this malfunctioning issue I have in the ball function. The code I have is the following: GOval initBall(...
1
vote
1answer
135 views

Ball bounces just above paddle

When I run the following code the ball bounces just above the paddle (around 10 pixels above the paddle). I haven't messed with the detect-collision function and following are my initPaddle() and code ...
0
votes
1answer
248 views

How to use strcmp correctly in PSET4? (Using it cause my whole program to stop)

I am faced with a very strange problem on PSET 4 (Breakout.c)... The following is my code (main portion). All is well - the ball moves and bounces off the paddle and off the walls (not yet the bricks) ...
1
vote
1answer
110 views

what's the error in the below function

I tried to make my own function in pset4-breakout to move the paddle but when i run and take my mouse to the output window I always get segmentation fault. I have tried gdb also but still i'm not able ...
-1
votes
2answers
271 views

Why breakout does not restart after placing a new ball and clicking?

My breakout program is getting near completion. I found the following problem, though. After hitting the bottom, I'm erasing the old ball, placing a new ball in the same manner as in the starting ...
0
votes
0answers
121 views

Paddle movement: how to check for window's boundaries more efficiently?

I just implemented my paddle movement function: // height and width of game's window in pixels #define HEIGHT 600 #define WIDTH 400 // Looks of the paddle #define PADDLE_WIDTH 80 #define ...
0
votes
1answer
50 views

Whenever i start moving my ball the paddle disappears

Till the time my ball is at rest i can see my paddle but as as i start moving my ball my paddle disappears. My code for paddle is: and my code for ball is: please help me as i have spent hours to ...
1
vote
0answers
46 views

Why redefining `bool` primitives in 'SPL' as a typedef (rather than using stdbool.h)?

While reading through files included in /spl library (Stanford Portable Code), downloaded with pset4.zip distro, I came across this definitions in cslib.h: /* * Type: bool * ---------- * This type ...
0
votes
1answer
56 views

Polygon paddle instead of rect

I tried to construct a GPolygon (code following) for my paddle instead of a GRect. I found that the detect collision function didn't work for this paddle, but i can't really see why. Perhaps its ...
-1
votes
1answer
200 views

Unable to get zip file for problem set 4

I checked and rechecked, and I am nearly certain I copied the instructions correctly from the Problem Set 4 in order to download the zip file, but I keep getting the following error message: ERROR 404:...
1
vote
1answer
54 views

When I implement initBricks() I no longer see the ball or the paddle

If I comment out my code for initBricks(), I can see my paddle and ball. When I implement initBricks(), I can no longer see them. I can't figure out why. (The bricks look like they should--at the top....
1
vote
0answers
106 views

Can't run pset4 files outside of appliance

I usually use Ubuntu instead of appliance for programming, cause I feel much more comfortable that way and Ubuntu is the OS I use everyday. For that reason, I have downloaded the C compiler and the ...
1
vote
2answers
91 views

Problem uploading pest

I have tried to upload the zip file with my pset4 code to the CS50 submit function several times. I can add the files, but when I hit the upload button, the file appears to upload (the bottom green ...
0
votes
0answers
67 views

Play sounds using the SPL

I would like to include sounds in the game Breakout. I tried a simple test to get a sound file to play with the following code: ... #include "sound.h" int main(void) { Sound paddle_sound = ...
1
vote
1answer
66 views

In breakout, why use 12 char to store an int?

Here says: Why did we allocate an array of size 12 for our representation of that int as a string? No worries if the reason’s non-obvious, but give some though as to how wide the most positive (or ...
-1
votes
1answer
169 views

(pset4) Why is the paddle not bouncing the ball?

Ok, soI have this code that makes it so that the ball just rests on the paddle instead of bouncing off. So, my solution would be to do something like break; but for if statements. Problem being such a ...
0
votes
0answers
42 views

make appliance 19 run smooth for breakout.c

Is there a way to make the paddle respond better? I am experiencing a major lag running it in appliance 19. thanks
0
votes
0answers
33 views

Pset4 srand48 Purpose [duplicate]

What is the purpose of srand48 in breakout.c? I understand how we should us drand48 later on but I don't understand the purpose of this line. Thanks!
1
vote
1answer
105 views

Paddle stops moving when ball is moving

The paddle in pset 4 stops moving as soon as I have gotten the ball moving. What is the correlation between these two events? // keep playing until game over while (lives > 0 && bricks >...
0
votes
1answer
396 views

pset4-breakout ball bouncing

On Pset4 "bounce" Can anyone please help me in bouncing the ball at angles after it touches the window edges and paddle?! I mean is what all the math computation involved in it?? a pseudocode highly ...
0
votes
1answer
897 views

Why won't GDB work with my breakout draft?

My breakout program runs (sort of) with a few bugs. When I try to use gdb to help fix them, I get this: (gdb) break main Breakpoint 1 at 0x804a0e3 (gdb) run Starting program: /home/jharvard/Dropbox/...
0
votes
1answer
478 views

calling srand48 rand vrs srand

I was tinkering with the bounce function in pset4 trying to get the ball the bounce randomly around the window. I am getting stuck with PRNG. I just can't seem to get it to work using the srand48 ...
1
vote
1answer
188 views

Why won't my identical copy of breakout.c compile?

I'm approaching pset4 (Breakout) by making an exact copy of breakout.c, which I've named breakout1.c. This should let me insert my code into the copy and still have the original breakout.c to refer ...
0
votes
1answer
52 views

Why using variable of double type for storing number of pixels? pset4

I have just realised that in pset4's short named "click" (at 2.30) here David prints out the coordinates of the click as floating point numbers. The number of pixels is finite so they could be ...
1
vote
1answer
312 views

Cannot get both paddle moving and ball bouncing at the same time (pset4)

I can get either the paddle following the cursor, or the ball bouncing, but not both at the same time. I've succeeded in making the ball bounce code loop within the while loop, by enclosing it in an ...
0
votes
2answers
344 views

pset4 velocity & ball's angle

I'm stuck in step 6. I have understood how to make the ball bounce on the window's edges but I cannot figure out how to make the ball move in an angle. I assume that it has to be some combination of Y-...
0
votes
1answer
445 views

Compilation error when using #include “gwindow”

When compiling a game program I keep getting an "unable to find" error directed to the Stanford Portable Library (#include gwindow). I have tried unzipping all files in pset4, searched Google and ...
0
votes
1answer
121 views

Why is my ball not being displayed?

Is there something wrong with the syntax because the ball is not being displayed on the window? Here's my code while(true) { GObject object; // initialized the velocity along x and y axis ...
1
vote
1answer
97 views

Converting an int to a hex string

In pset4 I want to create randomly colored bricks. To that end I created a function that returns a hex string. When I run it I get a segfault. Using gdb I have narrowed down the issue to the below ...
-1
votes
1answer
163 views

In pset4 the paddle in not moving and i am a little confused velocity and angle of ball?

while (lives > 0 && bricks > 0) { GEvent event=getNextEvent(MOUSE_EVENT); if(event!=NULL) { if(getEventType(event)==MOUSE_MOVED) ...
0
votes
0answers
131 views

Nothing inside my “while (lives > 0 && bricks > 0)” loop works in pset4

I've implemented the paddle movement (and very basic code for the ball to move just one way for now) inside the said loop, but none of it works and I can't understand why that would be the case. Is it ...
2
votes
2answers
272 views

Breakout slows down just before finishing the game

Just before finishing a game of Breakout, the game start to move very slow and the paddle behaves weirdly. The game works fine for the first 40 bricks. What causes this? This is my code: GObject ...
0
votes
0answers
72 views

pset4 getting slow

Definitely I have some memory problems, could someone help me to fix it? The game is working fine except that gets very slow when I reach half of the game.
0
votes
1answer
160 views

drand48() Invalid Operands

This is my code: int min = 6; int max = 9; double x = min + (drand48() * 10) % (max - (min - 1)); Console Error message: Any idea what I am doing wrong?
0
votes
1answer
281 views

Breakout: Bouncing the Ball Up and Down

I'm not sure how to make the ball bounce up and down. Here's my code: while (lives > 0 && bricks > 0) { double velocity = 2.0; move(ball, 0, velocity); if (getY(ball) <...
0
votes
3answers
420 views

pset4 Ball is not moving

Issue: the ball is not moving. Code: // keep playing until game over while (lives > 0 && bricks > 0) { while (true) { // check for mouse event GEvent event = ...
0
votes
1answer
53 views

Undefined reference to `updateLives' pset4

I am getting undefined reference to `updateLives' pset4 when I try and compile breakout. I also get undefined reference to 'initLives'
2
votes
1answer
150 views

Bricks don't appear on screen

I initialized the first bricks position, then made two for loops inside of which I created a GRect object, set its color and added it to the window and also adjusted the brick's location for each row ...
-1
votes
1answer
69 views

Why do we need 3 characters to store integers as strings?

I don't understand how this code works: for (int i = 50; i >= 0; i--) { char s[3]; // convert i from int to string sprintf(s, "%i", i); } Why do we need 3 characters to store 50 ...
-1
votes
2answers
133 views

Breakout questions

I'm not done implementing breakout yet, in fact i just got started! But when i try to run in in the terminal (./breakout) and then close the window, why does the program still run after that? I know ...
5
votes
1answer
687 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) { ...
0
votes
1answer
355 views

Why is this code unable to bounce the ball

In my code for breakout, the ball is unable to bounce up and down, though the same code works in bounce.c for bouncing the ball vertically! Here's the main part meant for moving the ball: while (...
2
votes
1answer
812 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(...
1
vote
2answers
589 views

Make label with different name's other than label.c

My question is why I cannot simply make a different version of label.c with another file name? Let's say I save it as labelTest1.c; I get this error: jharvard@appliance (~/Dropbox/src5m): make ...
2
votes
1answer
84 views

Stanford library is missing GRectangle and getBounds

I'm doing pset4 which uses the Stanford Portable Library. David mentioned the documentation is buggy but it appears wrong in some parts. In particular there is a type GRectangle and the method ...