Skip to main content
6 votes
Accepted

Pset3 Helpers.c Frequency Not Working

For "A4", this returns 440 for me. Note that C's ^ operator is bitwise XOR, not power. Also, in C, 1/12 equals 0 (integer division truncates, you could avoid this by using floating point values like ...
Blauelf's user avatar
  • 21k
3 votes
Accepted

Problem with pow() function, int frequency, helpers.c, pset3, music

(pow(2, index / 12) the issue is that both index and 12 are integers, so with integer division, the result will always be a whole number. Try using 12.0 instead of 12 to force a floating point ...
curiouskiwi's user avatar
  • 18.7k
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

find.c compiles but fails check50 - I believe binary search is to blame

The reason that the other questions aren't helping is that you've come up with a problem that appears to be unique. Take a look at the following code, particularly the test condition: if (values[...
Cliff B's user avatar
  • 69.1k
2 votes

helpers.c Doesn't Compile

You have come to make helpers only because check50 might have prompted you a frown at :( helpers.c compiles. Whatever changes you make, compiler throws the same error. Because helpers.c doesn't have ...
Haripriya R's user avatar
1 vote
Accepted

PSET3: Music, getting this error 'expected exit code 0, not 1'

You say that your submission failed at this point: :( helpers.c compiles Log running clang -std=c11 -o is_rest is_rest.c wav.c helpers.c -lcs50 -lm... checking that program exited with status 0... ...
Peter Pesch's user avatar
  • 1,009
1 vote

PSET3 - Find (More) - Debugging and bubble sort issues

if (values[mid] << value) ... else if (values[mid] >> value) What are the operators >> and << and what are the operators > and <??? Of course, this is no ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

Check50 is claiming that it's recieving an exit code of 0 rather than 1 (different scenario)

This code will never find anything unless value == midpoint. On each pass through the loop, it updates the min or the max, but it never updates midpoint. Since midpoint never changes, the loop will ...
Cliff B's user avatar
  • 69.1k
1 vote

Mess of Error Messages From Clang

You do not need to make the helpers.c file because it is not an executable. It contains functions that will be used by the find program. Once you finish implementing the search and sort, just save ...
Tsundzukani's user avatar
1 vote
Accepted

Any help is appreciated with pset3 check 50

Test your programme with a simple array that's not sorted. You'll find your swapped == 0 will never trigger and you end up in an infinite loop. Reason for that is that you set swapped = 1; within the ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

pset3: sort and search work in separate files, but my helpers.c doesn't work

Your search function never returns true. Ever. if (value == values[m]) { return 0; } return 0 is the same as return false. It should be return 1 or return true.
robert_x44's user avatar
1 vote
Accepted

pset3 find- check50 Why doesn't find returns frowning face

Actually, the code is failing every test, but check50 doesn't see it. The problem is that the search function will return true 100% of the time, no matter what. The problem lies in the while loop. In ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

PSet 3: binary search help

There are two problems with this code. First, while binary_search() calls itself recursively, it doesn't return the result. See http://cs50.stackexchange.com/questions/9691/pset3-binary-search-...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

Puzzled by Pset3 - find less confortable- sorting output

Whenever an unexpected value, particularly 0, suddenly appears in the sorted list and the largest value disappears, look for code that goes beyond the end of the array. This is a somewhat common ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

'int' but the argument has type 'int * problem with sort in helpers.c

The array name "values" is a pointer, it does not serve us %i, to show the complete array it is necessary to use a for loop: for( int j = 0; j < n; j++) { printf("%i", values[j]); } A void ...
MARS's user avatar
  • 5,179
1 vote
Accepted

Helpers.c binary search help

Hmmm.... infinite loop problem. Looked at the code. Small_index gets reset nicely on each pass through the while loop. High_index gets reset nicely too. So, after the low or high limit gets ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

How to fix z++ in for loop not increasing the value of z?

This would be the result if : count is a 51 (or more) element array count[39], count[40], count[41], count[42] are all 1, rest of the elements are 0 values = {42,40,39,41} This for (int y = count[x],...
DinoCoderSaurus's user avatar
1 vote

Binary Search Pset 3 help

The only thing wrong in your searching algorithm that i'm seeing is that you have your if statement followed by a second if statement. I believe that that should be an else if.
Davis's user avatar
  • 144
1 vote
Accepted

pset3 - find Why do we need a limit at 65535 to pass check50?

It has to do with LIMIT vis-a-vis run time. If LIMIT is defined 65536 the check50 fails. If LIMIT is defined 65535 check50 passes. Suspect it is timing out, since part of the exercise is "running time"...
DinoCoderSaurus's user avatar
1 vote
Accepted

helpers.c still returning the wrong exit code?

Doesn't look like anything is working correctly. Unless n=0, the code will return false every time because the while loop will not execute. while(last<=first) There's also the issue that if the ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

Assigning an empty array with malloc has a random number in it

In the description for malloc, note the following sentence: DESCRIPTION Allocate size bytes of memory. Unlike calloc, malloc will not pre-set all allocated memory to zero. This tells you what's ...
Blauelf's user avatar
  • 21k
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

pset3 helpers.c ERROR

helpers.c does not contain a main function, so it cannot be compiled into an executable. Its code is used in find.c, make find instead of helpers, using either make find or clang -ggdb3 -O0 -std=...
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

How do I test sort function in helpers.c pset3?

The simple approach works. Just before the return, create a for loop and print out the array in order. Having said that, your sort isn't working. You do a great job of swapping j and k. The problem ...
Cliff B's user avatar
  • 69.1k
1 vote

linearsearch in helpers.c pset3

Just found it: I had to "make find " before testing for value 127 (./generate 1000 50 | ./find 127) !!
Samir-B's user avatar
  • 11
1 vote
Accepted

Pset3 recursive binary search function - check50 gives me four :( and I don't know why

Based on the comments in your code and without doing much analysis, I'd say that you have fallen victim to a very common error for new programmers. A bool is either true or false. It can also be ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

Pset 3 helper.c issue

It means that you tried to make helpers when you should have done make find. Part of this lesson is to understand how to create an executable from multiple source code files. Since helpers.c has no ...
Cliff B's user avatar
  • 69.1k
1 vote

Pset3 Problem with binary search

I'm not sure how much help I'm allowed to provide. Please let me know if I went too far or if I'm allowed to provide more specific help. I think "a", "z" and "mid" should be positions on the array ...
Alexis's user avatar
  • 25

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