Hot answers tagged

7 votes

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

The warning (converted to an error due to the -Werror option to clang on the appliance) control may reach end of non-void function Says that you've a function in your program that's declared to ...
user avatar
  • 17.4k
6 votes
Accepted

pset3 FIND: Strange clang error whenever I compile code

helpers.c has no main function. You need a main function in every C program, it's the program's starting point, so to speak. Anyway, the problem with your command line argument is you're missing the ...
user avatar
  • 458
5 votes
Accepted

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

Have you written the sort and search functions in helpers.c? That is one of the assignments in the problem set. find won't work until you've actually written the code. As the pset says: And now ...
user avatar
  • 18.3k
5 votes
Accepted

pset3 find INT_MAX

INT_MAX is defined in limits.h, which is a standard C header. INT_MAX: Maximum value for an object of type int (32767 or greater) You may wonder why find.c needs that? int straw = GetInt();...
user avatar
  • 18.3k
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 ...
user avatar
  • 63.4k
3 votes
Accepted

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

In the search function, try replacing if (values[middle] == value) by if (values[middle] == value || values[middle+1] == value). Because middle is an integer and middle = (lower + upper) / 2; works ...
user avatar
  • 3,316
3 votes

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

Looking at the distribution code for find.c, we can see this line near the top of the file: #include "helpers.h" That header file, helpers.h, contains only the prototypes for your search and sort ...
user avatar
  • 2,136
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 ...
user avatar
  • 63.4k
2 votes

pset3 FIND: Strange clang error whenever I compile code

To deepen what Andrej and Cygni_61 both correctly said, well, you need to 'make find' instead of 'make helpers', which I assume is what you were doing from the clang command. In the Makefile, you can ...
user avatar
  • 205
2 votes

pset3 FIND: Strange clang error whenever I compile code

To deepen what Andrej correctly said, consider helpers.c as an auxiliary file where helper functions reside. When you write complex code, you can distribute your fnctions into different files: this ...
user avatar
  • 1,156
2 votes

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

If you're sure that everything is correct, you may drop Rob Bowden a note at rob@cs.harvard.edu! Please mark this as best answer to take this question out of the unanswered list. Thank you Kareem.
user avatar
  • 1,211
2 votes

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

We are not given the source code for search() in helper.c. We are asked to implement this search() function using linear search first then binary search. And since you haven't implemented any of these ...
user avatar
2 votes
Accepted

Pset 3 - Find and Helper.C

You are comparing min and max. You should be comparing values[min] and values[max] Otherwise, you end up with, for example: {41,42,43} so n = 3 min is 0, max is 2 mid is 1. if 1 == 42 else ...
user avatar
  • 18.3k
2 votes
Accepted

pset 3 GDB: "no executable file specified"

To debug "find" with gdb, enter the following command: gdb find You need to enter the filename of the executable as a parameter following gdb on the command line. Don't use ./ or .c when you enter ...
user avatar
  • 63.4k
2 votes
Accepted

Pset3 Sorting Help a bit of out of the scope

You must tell the compiler to link the cs50 library by using the -lcs50 flag. The full command should be: clang -ggdb3 -O0 -std=c99 -Wall -Werror sort.c helpers.c -lcs50 -o sort If this answers your ...
user avatar
  • 7,326
2 votes

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

The reason why 100 is ignored is because you're comparing values[min] with values[j] only. And since j is initially set to i + 1 which is 1, values[0] is totally ignored. The role of the nested loop ...
user avatar
  • 17.4k
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 ...
user avatar
  • 63.4k
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....
user avatar
  • 1,424
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 ...
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 ...
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 ...
user avatar
  • 20.7k
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[...
user avatar
  • 5,172
1 vote
Accepted

PSET3 search and sort, programm crashes in given find.c file

find.c has been very stable, so I'm confident that the problem isn't there. It sounds more like you are experiencing infinite loops and not program crashes. I'm also highly suspicious that the problem ...
user avatar
  • 63.4k
1 vote

Concatenation values to array

Say your array is 3,2,1 On the first pass of your loop (i = 0) your array will become: 2,3,1 Then i becomes 1 and on the second pass it will become: 2,1,3 This is good, as now the 3 is in the right ...
user avatar
  • 264
1 vote
Accepted

What file am I suppose to compile to see my output in Pset3 Sorting?

Your code doesn't print anything because you have a return statement before the for loop that would print the sorted array. Either delete return completely or even better move it below the last for ...
user avatar
  • 7,326
1 vote
Accepted

find.c does some things which are not written in itself

Look at the implementation of GetInt() from http://cdn.cs50.net/2011/fall/lectures/5/src5/cs50.c. /* * Reads a line of text from standard input and returns it as an * int in the range of [-2^31 + 1,...
user avatar
  • 7,326
1 vote
Accepted

Find.c doesn't do anything

You while-loop never finishes because n never changes. You need to either rethink your logic so the loop terminates when the value was not found, returning false, or detect when there's no values left ...
user avatar
  • 60
1 vote

Help on helpers! pset 3 - can't find the error!

Classic array overshoot problem. Look at your sort code inner for loop. for(i=0; i<n; i++) if (values[i] > values[i+1])... The values[] array has n elements, numbered from 0 to n-1. Your ...
user avatar
  • 63.4k
1 vote

pset3-helpers-expected expression

From what I can see, you have at least one mismatched curly brace that isn't paired up with another. Make sure that all of your curly braces are properly paired. If you highlight a curly brace or a ...
user avatar
  • 63.4k
1 vote

pset3 find - gdb with generate as pipe

I answered on your reddit post but I'll post it here too: Run generate and send it to a text file, then run find under gdb using the text file as input ./generate 581 50 > 581nums.txt gdb ./find (...
user avatar
  • 18.3k

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