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
1
vote
1answer
433 views

pset3 - 4x4.txt winning sequence not working - problem with move function?

When I play fifteen myself it works with any board size; the 3x3 winning seq also works, but the 4x4 one does not finish and stops while repetitively trying to move tile 2147483647.. GDB did not help ...
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 ...
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....
0
votes
2answers
532 views

pset3 fifteen move creates double numbers

So my move function finally compiles, but when I run the program and chose a legal tile (i.e. one by the blank) the blank turns into the tile I picked. So from this: 8 7 6 5 4 3 2 1 ...
0
votes
2answers
246 views

pset3 fifteen move doesn't compile

First of all I know there are two questions very similar to this one but the answer I'm looking for is not there. I'm working on my "move" function for fifteen in pset 3. I keep getting the "control ...
0
votes
1answer
106 views

What is if(!move(tile)) and can I change it?

I don't understand the if(!move(tile)) condition in pset3. Can anyone please explain it to me? Can I change this code?
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
1answer
214 views

Segmentation fault core dump with find and helpers.c

I have been working on find.c for the last three days, without success. When I run check50, 50% of the time it compiles helpers.c but then does not find 42 as it is supposed to. The other 50% of the ...
0
votes
1answer
99 views

Values found aren't the ones submitted?

I'm working on pset3, and I think I've finished helpers.c. It sorts correctly, and I can't find any mistakes, but it does something really weird. If I enter the values 1, 2, 3, 4, 5 into find.c as hay,...
0
votes
1answer
6k views

What does “error in backend: IO failure on output stream” signify?

I altered the code in helpers.c in such a way that when the difference between the find value and the "haystack" value equals zero the program returns true. However find will no longer compile and ...
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 ...
0
votes
1answer
465 views

pset 3 “control may reach the end of a non-void function” [duplicate]

I know what this error means, but how do I fix it? I'm using a if... else... function, so I'm not sure how to improve upon that. Thanks!
0
votes
2answers
499 views

How to pass grid values to draw in pset3

I've just finished coding init and have started draw but I'm not sure how to pass on my grid values to the draw functions. Especially as the values may change as the user plays the game. I've tried to ...
2
votes
1answer
787 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
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 ...
-1
votes
1answer
303 views

pset3 won - segmentation fault?

I've tried a solution for function won but I always get segmentation fault (core dump). First for loop is row It doesn't work... always this segmentation fault.... what am I doing wrong? please help!
0
votes
1answer
453 views

Can't download .zip file for pset3

I have problems downloading the pset3.zip file according to HTML specifications for problem set 3. I have tried running update50, connect50, I have logged off and back in again. The terminal isn't ...
0
votes
1answer
433 views

Pset 3 - find.c is not working

I have compiled find.c, generate.c and helpers.c. When I compile make all, I get the following error message: jharvard@appliance (~/Dropbox/pset3/find): make all clang -ggdb3 -O0 -std=c99 -Wall -...
1
vote
1answer
274 views

won() Doesn't Work Properly

My won() function works properly when the board dimensions are 3 x 3. However, it doesn't work properly when the board dimensions are 4 x 4. What could possibly be wrong? for (int i = 0; i < d; i++...
1
vote
2answers
99 views

The Case of the Disappearing Tiles

I just finished trying to implement my move function. It seems to work to a certain extent, except that some of the tiles keep turning into blanks. I have the following code for my swapping: for (int ...
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: ...
0
votes
1answer
252 views

My sort and search functions don't work for find.c - look at my code?

I try inputting ./find 31 and then the list 30, 31, 32 and it still says it can't find the needle in the haystack. :( I don't know if it's my search function, my sort function, or both. Help! The ...
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
1answer
840 views

How to test helpers.c

I'm just wondering the best way to test out sort and search in helpers.c. Since the file won't compile/run on its own, how can I test the code that I'm writing?
0
votes
1answer
108 views

Dereferencing 2d pointer to print board

I've used pointers to help create my game of fifteen grid, and now I want to print out the board using 'draw'. The function works to the point that the board prints, but instead of array elements I ...
0
votes
1answer
522 views

helpers.c is not sorting my array and I'm running low on ideas on how to fix it

My first question on this board and I really need some help in order to figure out what could be wrong with my code. I decided to go with a a selection sort but as soon as I run ./generate 2 2 in ...
0
votes
3answers
681 views

Error in my logic? Pset3 Won

Could someone explain me why my superb idea isn't working? Okay, perhaps it isn't that superb but it was my original own idea. In pset3 fifteen game when seeing if the game is won, I first created a ...
0
votes
2answers
118 views

GDB stops at GetInt()

I tried using GDB for my Game of Fifteen but I can't get to the part of functions move and won because GDB stops when command line asks for tile to move. This has something to do with GetInt. GDB ...
0
votes
1answer
93 views

Why isn't pset3 marked? [duplicate]

It's not really a question about coding. I was just wondering why my pset3, which I submitted two months ago, hasn't been marked yet. Sorry about using this forum, but I'm taking the course through ...
0
votes
2answers
72 views

How to define something in a loop only once and have it remain after function ends and is called again?

for pset3 my move function is the following: int j = 0; for(int i = 0; j < d; i++) { if(i == d) { i = 0; j++; } if(board[i][j] == tile) { printf("%i, %i", i, j); ...
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 = ...
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 ...
1
vote
2answers
98 views

Do we have to implement game of fifteen in pset3 using graphics?

Does fifteen.c had to be implemented in graphics, by including graphics.h and creating the tiles as graphical objects?
0
votes
2answers
851 views

Pset3 won-function works only with 3x3 board. Where am I wrong?

Pset3 won-function successfully passed this test ./fifteen 3 < ~cs50/pset3/3x3.txt only for a 3 × 3 board. For a 4x4 board the program's output is: 1 2 3 4 5 6 7 _ 9 10 12 ...
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?
0
votes
2answers
2k views

pset3: sort — having trouble connecting all the dots

I'm not sure what to work on. The pset3 instructions say: Go ahead and implement sort so that the function actually sorts... Odds are you’ll want to implement bubble sort, selection sort, or ...
0
votes
2answers
189 views

How to Stop Making my move() Function Keep Printing “Tile to move”?

Please explain me why fifteen's move() function is successfully compiles and, runs but keeps printing "Tile to move:" without printing anything else like invalid input and so on. GDB gives me the ...
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?
0
votes
1answer
510 views

How to Print the Blank Tile in the Game of Fifteen

In Game of fifteen we are asked to print a blank space at the end of the game, they fistly tell us to put the last number as any Int, then they ask us to print something that is not the int we chose, ...
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
2k 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?

1
21 22 23 24
25