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
0
votes
2answers
3k views

Pset 3 - Find and Helper.C

Question about find and helpers.c. When I run check50 on my code, I get the following error below: :( doesn't find 42 in {39,40,41} \ expected an exit code of 1, not 0 :( doesn't find 42 in {39,...
0
votes
0answers
135 views

I can't get search to work when value == value[n]

I'm trying to implement a recursive binary search in helpers.c. When checking my code with check50, everything works except: :( finds 42 in {40,41,42} :( finds 42 in {39,40,41,42} So obviously ...
0
votes
2answers
422 views

pset3, move function

Here's my move function. The problem here is i know im not following the instructions. Because i don't understand why do i need to track and how to track the blank tile. My function works as expected. ...
1
vote
1answer
230 views

Global variables to store the position of the blank space?

I tried to implement a leftward movement in game of 15. I encountered a problem. The program can only call move function once and it doesn't work after that. I use 0 to as the representation for the ...
0
votes
2answers
152 views

Selection sort does not sort the unsorted portion once no swapping position is reached?

I've been struggling with this bug for almost 2 days, but so far no success. If anyone could point out what is wrong with my code, I would appreciate it very much. Using my own random numbers (100, ...
0
votes
1answer
193 views

Trouble with binary search

Using gdb, I found the problem is when the left_values is not there because if I try print left_values right after declaring it, it tells me No symbol "left_values" in current context. after ...
0
votes
1answer
391 views

Got an expected expression error on strlen ( values[] )

I'm working on CS50 pset3 helpers.c, trying to implement my own search algorithm (first TODO in the helpers) like the following: Make helpers came back with the following error message. Values[] is ...
0
votes
2answers
733 views

What's wrong with this binary search implemented using recursion?

This is pset3 and I've tried making it work for numerous hours. It always returns false whether the 'needle' is found in the 'haystack' of arrays or not. When typing this in the command window: ./...
0
votes
1answer
98 views

Values for tile locations are 0 in gdb

I'm not getting whats going wrong with my move and draw functions. When I trace the program through gdb I'm getting the 0 values for tile locations.
0
votes
1answer
297 views

Cannot implement swap function for fifteen pset3

I managed to write a swap function before attempting "fifteen" , but within the context of writing the "move" function, I just can't get it to work, despite following the same format. When I swap, it ...
0
votes
1answer
334 views

pset-3 move function

bool move(int tile) { int hold; for(int i=0 ; i < d ; i++) { for(int j=0; j<d; j++) { if(board[i][j] == tile) { ...
0
votes
1answer
59 views

pset3 - fifteen - /move - trouble moving the largest number

So, I can locate the blank tile and the called number to swap, swap them (although through a number of steps), and then print the new board. The problem arises when I move the largest number. The ...
0
votes
1answer
157 views

pset3- fifteen printing _

void init(void) { int i,j; for(i=0 ; i < d ; i++) { for (j=0 ; j < d ;j++) { do { board[i][j] = GetInt(); if(...
0
votes
0answers
1k views

What does clang's “undefined reference” error mean?

What do the following compilation errors mean and how can I fix them? jharvard@appliance (~/Dropbox/pset3/find): make helpers clang -ggdb3 -O0 -std=c99 -Wall -Werror helpers.c -lcs50 -lm -o ...
2
votes
1answer
151 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: ...
0
votes
1answer
93 views

`./generate 1000 50` generates different list of numbers for pset3

In the section Searching of this page of edx, in the last part where students recommended to check their programs by looking for number 2008, is a bug - there is no number 2008 among the numbers ...
0
votes
0answers
162 views

Move won't swap tiles

Both init and draw run perfectly fine, but no matter what I try with move, any number I give the program returns "Illegal move" My code was (i thought) running through each row and column until it ...
0
votes
1answer
191 views

“Expected expression” error in my Game of Fifteen code

My Fifteen code won't compile because of these two "expected expression" errors in my "won" section. fifteen.c:254:15: error: expected expression while (n !== d*d) ^ fifteen.c:...
1
vote
1answer
234 views

Debugging sort code

I've been trying to write code for the sort function. It's not working properly and going through gdb isn't helping. When trying to sort 5 numbers, it seemed to go fine in gdb, but still printed out ...
1
vote
2answers
581 views

Cannot unzip pset3.zip: “End-of-central-directory signature not found.”

Here is my input and the output. Any thoughts? I have downloaded other copies so don't think it is due to a corrupted file. Archive: pset3.zip End-of-central-directory signature not found. ...
0
votes
1answer
461 views

How to compile Game of Fifteen framework?

I'm off to a very poor start on Game of Fifteen. The first task mentioned in "The Game Begins" is: "Go ahead and compile the framework. (Can you figure out how?)" I haven't been able to, and would ...
0
votes
1answer
221 views

Why won't my nested for-loops compile?

I'm trying to use nested for loops in the "init" part of Game of Fifteen and can't figure out why my code won't compile. Here's the code: for (i = 0; i < d; i++) { for (j = 0; j < d; j++) ...
2
votes
1answer
777 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 ...
0
votes
2answers
362 views

Binary search algorithm only works for smaller arrays

I can't figure out what I'm doing wrong. My algorithm works for smaller arrays, but once the number of values increases, the program stops and I have to hit Ctrl + C. I thought maybe it was an issue ...
1
vote
1answer
647 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?
0
votes
1answer
104 views

Is it okay to check my code against a reference book?

Alright, so I've been having trouble making binary search (I think I either made an asymptote, or it degrades too quickly.), so I decided to see if my reference book had anything on Binary Search. It ...
1
vote
1answer
229 views

Piping generate pset3

I just wondering if some one can confirm for me that I understand what exactly is going on here when a file gets piped into another program. Generate is producing a certain number of random numbers ...
0
votes
0answers
78 views

Header files in helpers pset3

What is the rationale for the header files in helpers.c? For example there is cs50.h but not stdio.h even though the functions are all stdio except for bool which is in neither CS50 nor helpers. And ...
0
votes
1answer
168 views

How can I implement binary search without changing the search() declaration?

I am struggling to implement the recursive binary search function: We are not supposed to change the search() declaration, so I thought I will have to implement a separate recursive function for ...
0
votes
1answer
512 views

Linear Search not working

Alright, so, I'm not quite sure what's going wrong here, but maybe you people could help. My implementation of linear search in pset3 will return false no matter what (well, specifically I've only ...
0
votes
0answers
123 views

segmentation fault in pset 3

i have written init and draw function in init i have made 2 nested loops and given value to each element starting from position (0,0) = d*d-1 till the last element and i have printed the given ...
0
votes
1answer
736 views

Binary search question

I'm currently struggling with the binary search in pset 3 and I think I already found out how to implement it. I just really can't understand why, after return res;, the program does not leave the ...
0
votes
1answer
325 views

How and where to write code to check around tile? Pset3, Game of Fifteen

Been killing my head for too long with this. I get that we check around the tile when we find it in our loop, but then what? I understand completely, conceptually... yes, check around the tile for ...
2
votes
1answer
169 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
2answers
845 views

How to set up the board using init and draw functions

I am working on PSET3 Fifteen and am really unsure of what I am doing with the init function. I have a nested for loop – but I don't know what to do with the values. I then move on down to draw and I ...
1
vote
1answer
475 views

Swap 2 and 1 after looping, pset3, Game of Fifteen

I don't know why my positions at 2 and 1 in my odd numbered tiles are not swapping. Here is a mix of pseudo code plus my swap conditional. See anything that is wrong? Thanks. // board, whereby ...
0
votes
0answers
114 views

what's wrong with my linear search?

I don't get this. I did a whole lot of debugging with gdb, and somehow move returns false automatically just after this simple search for the tile. int p=0,q=0; for(i=0;i<d ;i++) { for(j=0;j<...
0
votes
0answers
310 views

Swap function in helpers.c file

I have successfully completed the linear search and sort functions in the helpers.c file for problem set 3. I included the swapping steps within the sort function directly and everything worked ...
0
votes
1answer
1k views

pset3 fifteen won function isn't working?

I've been trying to write the won function for days, but it has never worked correctly. I can't find any flaws in my logic, so can somone help me figure out what I'm doing wrong? ebool won(void) { ...
0
votes
1answer
136 views

control may reach end of non void function in move [duplicate]

This is my code for move: for(i=0;i<d;i++) { for(j=0;j<d;j++) { if(a[i][j]==tile) { e=i; f=j; } ...
4
votes
1answer
510 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,...
1
vote
1answer
181 views

Pset3, After haystack values typed, just blank on the Command line

I am almost done with my Binary Search and yet when I test it, it does this strange thing. I run ./find (some number) and it prints out the haystack[] values one by one as I enter numbers for those, ...
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 &...
3
votes
2answers
33k 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 ...
1
vote
1answer
590 views

Search function always false, haystack doesn't print a value

I feel like I am close, but not sure why my haystack values are not printing. I am trying to write linear search code for the search() function in helpers.c, and this is what seems to me to be the ...
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 ...
0
votes
3answers
622 views

pset 3 binary search

I know the logic behind binary search is simple but my code isn't compiling. I went along the lines of week 3's section. I am still getting compilation errors. int beginning = 0; int ending = n - 1; ...
0
votes
2answers
582 views

pset 3 game of fifteen: need help swapping tiles

I have been able to draw the board properly. I can locate the blank tile and tell when the blank tile is adjacent to the tile the user wants to move. My program warns the user when he/she selects a ...
0
votes
1answer
147 views

pset3 find.c corner case

I made a for loop for searching and sorting in the header file. Both loops start off like this: for (int i = 0; i < n ; i++) find.c compiles fine for me but when I put the needle at the end of ...
0
votes
1answer
2k views

“Expected an exit code of 0”

I get the following error when I check50 helpers.c: \ expected an exit code of 0, not standard error of "helpers.c:24:17: error: implicit declar..." Here is the source code of helpers.c: bool search(...