Questions tagged [pset3]

The problem set for Week 3 asks students to write code for a classic puzzle game in the C programming language.

Filter by
Sorted by
Tagged with
8
votes
1answer
4k views

How to Check Sort Function with GDB

I've implemented my sort function in helpers.c and I have no clue as to how to check if it does actually sort. I've tried to call on the printf function so it can print out the sorted array, but find....
4
votes
1answer
495 views

pset3 find INT_MAX

In find.c, there's a conditional that references a constant called "INT_MAX". I looked through all the pset files and couldn't find any reference to this constant. What is it, what does it represent,...
3
votes
2answers
26k views

How to solve “control may reach end of non void function” error

When I try to compile my code, I get an error message that says "control may reach end of non void function." What does this message mean and how can I avoid this error? Here is the function that's ...
3
votes
1answer
81 views

Problem using howstuffworks

I was reading through material on howstuffworks for cs50 and am having trouble implementing one of the tutorial programs. Specifically, when I copy and paste the following code from page 11 (Arrays) ...
3
votes
3answers
416 views

Blank tile without using a variable

Regarding the blank tile in Game of Fifteen, can I avoid using a variable for the blank? In other words, can I just print an underscore when I reach zero in my array?
3
votes
2answers
683 views

My pset3 find code completes all tasks using check50, but gradebook says it's wrong

I can't seem to figure out why the CS50x gradebook says that my find code is wrong but when I check the exact same code using check50, I get all smileys. I did everything as per instructed. I ...
3
votes
1answer
297 views

Whodunit No Files

I'm about to start pset3, but the terminal keeps disconnecting, and so I refresh the page. When it opens again, the CS50 Lab no longer has any of the files, and I can't see what the copy.c files does ...
2
votes
1answer
786 views

Where can I find 3x3.txt?

So I've gotten to the end of my coding for fifteen and sure, I could try and solve it myself (I'm lazy), OR I could load up the 3x3.txt file. However, I'm having trouble finding the location of this ...
2
votes
1answer
5k views

Pset3: Plurality - Weird output!

This program is for counting the plurality for a list of candidates, Check Description for more info, The program works like this: Enter the candidate's name as an argument when running the program ...
2
votes
2answers
512 views

Find.c does not find the value that I put in haystack

For pset3, I have to download pset3.zi and unzip it. I followed all the steps in the instruction. However, when I get to the program find.c, there's a problem. The program seems like not working ...
2
votes
3answers
3k views

helpers.c Doesn't Compile

I'm trying to compile helpers.c (pset 3), but it doesn't compile successfully. It gives me the following error: jharvard@appliance (~/Dropbox/pset3/find): make helpers clang -ggdb3 -O0 -std=c99 -Wall ...
2
votes
1answer
838 views

Pset3 Helpers.c Frequency Not Working

Right now I am working on Pset3 with Music. I'm focusing on getting the frequency (in Hz) of all the octaves of A. I am including accidentals in my work as well. The problem is that A4 returns 449 ...
2
votes
1answer
2k views

Selection sort seems right, but the values are not sorted

I have been running gdb on this, and it's true, the values are not sorted. But my logic seems fine. This is the selection sort, anyone know what I am missing? int min, hold, i, j; for (i = 1; i &...
2
votes
2answers
352 views

why can't I compile the program that I wrote to test helpers.c?

I've made a program to test my sort function. The only problem is that when I try to compile it gives me the "undefined reference to 'sort'" error as seen in the below: For context, I have taken the ...
2
votes
2answers
263 views

Why Aren't My Last Two Tiles Swapping?

I'm trying to come up with something to change the tile numbers in the last two array slots, containing numbers 1 and 2 when I have an odd number of tiles. I thought this would work, but when I print ...
2
votes
1answer
169 views

pset3 duration itoa - with “&”

For 'duration' I used the following which works (at least within a testing file), using atoi on individual parts of the inputted string fraction s: double n = atoi(&s[0]); double d = atoi(&s[...
2
votes
1answer
891 views

Pset 3: undefined reference to sort error with exit code 1

Here is the error code. Tried Make All. Tried several different sort & search algorithms and coding. clang -ggdb3 -O0 -std=c99 -Wall -Werror -o find find.c helpers.c -lcs50 -lm /tmp/find-3c23ac....
2
votes
1answer
199 views

Segmentation fault testing for detectCollision returning NULL

I am trying to detect collisions between the ball and paddle or bricks. The difficulty for me is trying to determine if detectCollision is returning NULL. An excerpt from my code is shown below. This ...
2
votes
1answer
430 views

Why does accessing an out-of-bounds array element not cause a segmentation fault?

I tried to access an array element greater than which was passed in the search function but it did not cause a segmentation fault. Here is the code in which I was trying to access the element: bool ...
2
votes
1answer
168 views

Pset3 search: can't seem to find the last number

Everything else in check50 works, but my program can't find 42 in {40, 41, 42} and {39, 40, 41, 42}. I don't think it's sort's fault, and I've implemented search in the correct way (I think, at ...
2
votes
1answer
1k views

How does find.c know to use functions from helpers.c?

I've been beating my head trying to understand the second assignment for pset 3. It states in part: Notice that find.c calls search, a function declared in helpers.h. Unfortunately, we forgot to ...
2
votes
1answer
32 views

Fifteen: Error in a function I haven't touched yet

I am working on the last part of pset3 (game of fifteen). After trying out my code for the init and draw functions, I tried to "make" it and receive this message in the terminal (CS50 IDE). clang -...
2
votes
2answers
63 views

How to implement ANSI sequences in pset3?

I have a completely working version of fifteen and want to try to alter the ascetics using the ANSI ESC functions that are hinted at. I have looked at their implementation of the clear function as ...
2
votes
1answer
743 views

Pset3 Fifteen Check50 not Working

My code works when using the 3*3.txt as well as when I play it, but it is not accepted by check50. Here are my check50 errors: :) fifteen.c exists :) fifteen.c compiles :( init initializes 3x3 board ...
2
votes
1answer
1k views

why do we pass arguments to the main function?

I did not understand that ,why do we pass arguments to the main function? for example in pset3 generate.c main {int argc,string argv[]}. please explain?
2
votes
1answer
260 views

pset3 fifteen.c passes local tests but fails check50 with timeouts

My fifteen.c passes the following local tests by getting to "ftw!" in each case: ~/workspace/pset3/fifteen/ $ ./fifteen 3 < ~cs50/pset3/3x3.txt ~/workspace/pset3/fifteen/ $ ./fifteen 4 < ~cs50/...
2
votes
1answer
53 views

Can somebody please help me to better understand constant variables, and eof, and how they relate to pset3?

Can somebody please help me better understand what constant variables can be used for? I am currently on pset3 and i noticed that a constant variable called MAX is used in find.c and gets 65536...but ...
2
votes
1answer
146 views

How do I get to work gdb to check my Won function in game of fifteen

there is a staff implementation of predefined set of moves for a 3 x 3 board which can be executed by ./fifteen 3 < ~cs50/pset3/3x3.txt I was working on my Won function, can some one tell me how ...
2
votes
1answer
143 views

check50 error: CERT_HAS_EXPIRED

I'm using check50 to check my linear search algorithm in pset3, and it doesn't seem to be uploading or checking at all. Instead I get the message: Uploading.. CERT_HAS_EXPIRED and the second time: ...
1
vote
2answers
3k views

Pset3 Binary Search problems

I have tested the code presented in the picture and find this function always returns false no matter what number you search.There must be a problem in it but I can not see it!! Can anyone help me ? ...
1
vote
2answers
939 views

pset3 / move function

The program cannot recognize a legal ( or illegal ) move too. How did you check whether a move is legal or not? Here's my code block for testing: //check if the move is legal //posi and posj = i and ...
1
vote
1answer
3k views

How to Fix “control may reach end of non-void function” and “No such file or directory” Errors?

When I compile find, I get this error message error: control may reach end of non-void function When I then try to run the program ./find 14 I get this error message bash: ./find: No such file ...
1
vote
2answers
1k views

Pset3 Fifteen Move function

I dont even know how to begin the move function, can somebody give me some ideas please? Probably by searching the tiles position, but how can i do that?
1
vote
1answer
3k views

PSet3 Music Final check50 item

I'm on my final check for this pset. The last check I keep getting the wrong round direction. I need C#3 to return 139 not 138, seems like a simple enough fix but anytime I change the result and add ...
1
vote
1answer
955 views

PSET3 LINEAR SEARCH

Please help me with this: My code for linear search: // To check n is a positive int. if (n<0) { return false; } // To check if value can be found in values array. if values is found return ...
1
vote
2answers
26k views

How do I fix a “use of undeclared identifier” compilation error?

In the following code snippet: for (int column = 0; column < d - 1; column++); { board[&row][&column] == counter; counter++; make returns the following error: fifteen.c:140:19: ...
1
vote
4answers
132 views

Pset3: why are the j and i values not swapping?

Here is my code: for(int i = 1; i < n - 1; i++) { printf("%i\n %i\n", i, j); int j = i + 1; if(values[j] < values[i]) { int tmp = j; j = i; i = ...
1
vote
1answer
339 views

pset 3 plurality help: not sure how vote function is implemented

would like to get some clarification on how the vote function in pset 3 is being implemented. As the vote function has already been implemented for us in main and we are only required to amend the ...
1
vote
1answer
163 views

pset3 - recursive binary search not compiling

I wrote a recursive function for binary search in pset" and I keep getting the same error from clang: "control may reach end on non-void function" it is driving me crazy... some help would be very ...
1
vote
1answer
117 views

Segmentation fault when using move() in Breakout

could I get a little help with pset3 Breakout please? I want to get the ball to move and bounce - I modified bounce.c to do this beautifully but when I put the code into breakout.c, it compiles ok ...
1
vote
1answer
570 views

argc value count confusion

I'm having some confusion on Pset3. In the program "generate.c" there is an "if" condition for validating the argument counts. Here is the portion I'm having confusion : if (argc != 2 && argc ...
1
vote
2answers
561 views

pset3 fifteen won

I've been attempting many different ways to make this work and I either come up with everything stopping once the game looks like it's been won and an "illegal move" and "retry" message, or I end up ...
1
vote
2answers
253 views

Mess of Error Messages From Clang

I just started pset3 and when I try to compile my helpers function I get this crazy mess of error messages from clang. This is my code /** * helpers.c * * Computer ...
1
vote
1answer
4k views

move function, pset3

I'm having trouble with my move funtion in the game of fifteen. For some reason the chosen tile and the adjecent zero won't swop places. I've been working on this function for too long and reaching ...
1
vote
1answer
106 views

Breakout program freezes when i make it wait for click to start.

I have later done with waitForClick() function but want to know whats the problem with the below code. bool start = true; while (lives > 0 && bricks > 0) { // Creates a mouse ...
1
vote
1answer
331 views

Breakout - bounce off brick- why do I need to check for object == NULL?

When using detectCollision to get the ball to bounce off the paddle, I just need to check if detectCollison returns the object "paddle" and if so, reverse the movement. But for the brick, I have to ...
1
vote
1answer
499 views

Void init(void) or void init(int d)?

Why is the init function in fifteen not declared as void init(int), since it uses the integer d?
1
vote
2answers
128 views

pset4 Lives Unintentional infinite loop

I'm implementing part 9 of 10 in pset 4 when I found a flaw in my code. First, pseudo-code: If ball is below the screen remove ball Refer to initBall function to create new ball which is centered. ...
1
vote
3answers
23 views

PSET3 Runoff Help Please

for(m = 0; m < voter_count; m++) { for(t = 1; t < 4; t++) { string name = get_string("Rank %i: ", t); } printf("\n"); } } bool vote(int voter, int rank, string name) { ...
1
vote
1answer
21 views

Global Variable vs Local variables?

I'm trying to write a function that will be called in main(int argc, string argv[]) for pset 2: plurality. Inside the function, I want a for loop. I've written this: bool vote(string name) { ...

1
2 3 4 5
25