Skip to main content
4 votes
Accepted

pset3/find check50 frown helpers.c compiles. expected exit code 0, not 1

find.c and helpers.h cannot be altered. When check50 runs, it uses its own copies, so your alterations are lost. That will cause the compile to fail. You need to make all of your changes in ...
Cliff B's user avatar
  • 69.1k
3 votes
Accepted

Pset3 The file compiled but can't find the needle

So, I took a quick look at the code..... for (int i = 0; i < n; i++) { if (value == values[n]) Which element in the values array is being checked on each loop???? What's ...
Cliff B's user avatar
  • 69.1k
2 votes
Accepted

WHAT is wrong with this small bool snippet? PSET3. It always returns true. Even if the needle is not in the haystack

There are two issues to address here. The expected return value of this function is a bool, but you are returning an int. Now, it is the case that you can use 1 and 0 as true and false, respectively....
Peter's user avatar
  • 1,410
2 votes
Accepted

pset3 - Binary search not finding the element in middle

In testing, the code works fine. Is it possible that you have a problem with your sort function? Have you verified that sort is correct by printing out the sorted list with different test data? As a ...
Cliff B's user avatar
  • 69.1k
2 votes
Accepted

pset3 "Find" Seg fault issue?

You have problems with the array that sets your counting array to 0: int array_holder[max_value]; for(int c = 0;c < max_value;c++) { array_holder[c]=0; } Think about implementing a counting ...
Steve Bunting's user avatar
2 votes

PSET3:Find: Code works without the function, doesn't work with the function

C, by default, passes parameters to functions by value. That means when the function swap is called, two new variables, x and y are created, and the values of the integers are copied into them. When ...
Satanic Saint's user avatar
2 votes

pset3 find: seg fault (int array won't initialize to 0s)

I used the debugger on it, and it looked perfectly fine. temp[0] to temp[65535] were initially 0. Have you tried using debug50 on it, like ./generate 1000 50|debug50 ./find 127? Maybe the ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

pset3 bubble sort

My sincere recommendation is ... start again. You have two nested loops, each time the DO-WHILE loop begins, the min and max values are set to zero, as the end-of-cycle condition for while is values[...
MARS's user avatar
  • 5,179
1 vote
Accepted

Pset 3 find less comf. I'm trying to test my bubble sort but having IDE CPU related issues

You're causing an infinite loop. You're not doing correct bubble sort there. Bubble sort requires two nested loops, not three. If for example the inner loop used j as its counter, it would compare ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

pset3 find less comfortable helpers.c didn't found the needle!

Use while (left <= right) to loop as long as the search interval has elements. No need for break;. You compare value value to index middle, but you have to compare value value to middle value ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

cs50x pset3 find - Need help with the counting sort

One problem I see with your sort function is that you've made a third array (sortedArray[]) and filled it with sorted numbers from values[], but then you didn't do anything else with it. Your function ...
ArtemPetrov's user avatar
1 vote

C : error non-void function search - value (find)

Having the errors multiply shouldn't necessarily be looked at as the code getting worse. Rather, the new errors should be analyzed for what they are. Sometimes an error masks other errors, other times,...
Cliff B's user avatar
  • 69.1k
1 vote

1, red smiley with pset3 helpers, need help

This is a Selection Sort algorithm, I think the problem is in the declaration int min = 0; Every time the outermost loop min is always zero, what interests us is that there is a variable that stores ...
MARS's user avatar
  • 5,179
1 vote
Accepted

pset3 - find less / sort video availability

The URL should be updated in the spec shortly. Here it is in the meantime: https://www.youtube.com/watch?v=TYnkJckP1Ss
curiouskiwi's user avatar
  • 18.7k
1 vote
Accepted

pset3, 'Find' problem. Can't figure out what is wrong with my code

Search should change the interval start in case of value > middleValue Your sorting also needs fixing. You try doing selection sort, for that you'd store the index of the smallest element, not its ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

Pset3 - Find: I can't find what's wrong with my sorting algorithm...?

In search, move the calculation of mid into the loop, and make sure the /2 is outside the parentheses. The sorting algorithm has no potential for an infinite loop, and looks correct. Also, it's ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

Binary search implementation help please

Binary search means: You have a search interval, with left and right boundary. Is the interval empty? Yes => :( Value not found No => keep doing Calculate the middle index of the interval You ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

find.c in Pset 3; int straw = get_int(); ./generate 1000 50 | ./find 127; Why I can't see this pseudorandom numbers?

If you want to see the automatically generated numbers when you pipe them in, you just need to add one line after the get_int() statement: printf("%i", straw); Bear in mind that if you now run find ...
Steve Bunting's user avatar
1 vote
Accepted

find.c in Pset 3; int straw = get_int(); ./generate 1000 50 | ./find 127; From where and how it takes 1000?

get_int() has no knowledge of the "2nd argument from generate.c". Remember from the spec: You’ll be prompted to provide some hay (i.e., some integers), one "straw" at a time. As soon as you tire of ...
DinoCoderSaurus's user avatar
1 vote
Accepted

Pset3, find - so close, yet so far away ... from completing!

Go through your code and make sure all your {...} bracket pairs are in the correct place. I can see straight way that you're missing one in your sort function, not to mention what may be happening in ...
Steve Bunting's user avatar
1 vote
Accepted

pset3 buble sort() function works but it gives wrong output in helper.c

You have two problems with the last element, or the one just behind the array. In code for(i = 0; i < n && no_swap == false; i++) { no_swap = true; for(j = 0; j < ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

Pset 3 Helper: Linear search function implem/ header file won't compile

This error means that there was no main() in the source files. By doing make helpers it tried to compile the program using the default rule of building an executable based on the name given - helpers....
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

Pset 3: What's wrong with my binary search code?

OK, first your sort() is definitely wrong. By saying values[i]=values[j], doesn't mean that those two values are exchanged, so now both values[i] and values[j] have the value that values[j] had. ...
ChrisG's user avatar
  • 7,396
1 vote
Accepted

What i am doing wrong? (pset3 find)

You have a function that has a return type of void, meaning it should not return any values. return false; actually returns a value, a boolean value of false. Instead, you should simply have a ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

is this function correct? CS50 Pset3 (Find)

There are problems here. First, it only makes one pass through the array, so all it will do is push the largest value to the end. The rest of the list will likely not sort. Next, since i can increase ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

Should the condition have >= instead of == in find.c?

In addition to being the maximum value that an int can represent, INT_MAX is the value returned by the CS50 library's GetInt function in case of error or EOF (see man get_int!) Testing whether straw ...
kzidane's user avatar
  • 17.7k
1 vote

working with pset3

Unless the code is searching for a 0, it will never return true. You've created something called a shadow variable value inside the for loop and set it to 0, so it will always search for 0. A shadow ...
Cliff B's user avatar
  • 69.1k
1 vote

Why is const used in field.c of pset3?

No they are not the same: #define MAX 65536: This tells the compiler to swap all instances of MAX with 65536, it is not not a variable that exists in memory. const int MAX = 65536: This declares a ...
kluvin's user avatar
  • 1,223
1 vote
Accepted

Segmentation fault in find.c

There are two problems - an infinite loop and a parameter that is out of range. Infinite loop: In binarysearch(), when the target is not in the list, the recursive calls will eventually get to a ...
Cliff B's user avatar
  • 69.1k
1 vote

return false in pset3 in cs50

This error is usually caused by a mismatched pair or a missing parenthesis or curly brace. Since the full code isn't posted, it's impossible to know for sure where the problem lies, but the following ...
Cliff B's user avatar
  • 69.1k

Only top scored, non community-wiki answers of a minimum length are eligible