5

This seems contradicting that search function will return true when the value is found using for loop and then return false. Not really. A return statement is capable of returning from a function (i.e., ending the function's execution and returning control to the caller). A function either returns a value or it does not. In case it returns a value, the ...


4

The error message you're getting means the compiler isn't sure if the function will ever end (i.e. that there will be a return value under every possible eventuality). The problem lies in the first "else" in your function. We all know that n is either >=0 or not, but the compiler doesn't. It thinks that your code hasn't covered all possible scenarios. Remove ...


4

This is a common mistake. What your code does is simply checking whether the first element of the array is equal to the value. What you wish is to iterate over the whole array. But after checking the first element of the array, you simply give it a choice to return false if the the element you were searching for is not found. Instead, you should do something ...


2

In your for loop you have for (n = 0; n < values[n]; n++) The values[n] has the value of the nth element in the values array. So on the first iteration you have n == 0 and you check, is 0 < values[0]? then on the second iteration you check, is 1 < values[1]? When what you want to check is if n is smaller than the length of the array, not a value ...


1

there's certainly a problem...two actually... first of all, why is your first condition including 0 as a possibility? surely there can't be a list of 0 members. secondly, you do not give your for loop a chance to run, because you say else, return false, meaning it only checks the first value. I would suggest doing away with the else part... PS. return means ...


1

That code will only test the first element in the list. If the first element is not the target, it will return false. Instead, if the first, or any element in the list is not the target, it should do nothing in the for loop. It should just loop and test the next element. It should only return false after the loop has completed and the target has not been ...


1

argv[] is a list of arguments introduced from the comand line. If you want to itterate through ever char in a particular argument you can do it by: argv[x][i] where x is the argument number and 'i' every character of that argument. For examble argv[1][0] would point to the first character of the second argument.


1

You may not be doing anything wrong. As I recall (it's been more than a year), when you run the program (manually or with input from generate), it will always print out a prompt for "haystack[i]= ". When manually run, it will wait for you to input a number. When run against generate, it will print out all of the prompts without waiting, as you are seeing. ...


1

Your "small" program is a little complex, you can try the one I coded, based on your code to see if it serves you. The program accepts the entry of the number you want to search for the command line. The program can be improved a bit. #include <stdio.h> #include <cs50.h> #include <stdlib.h> #include <stdbool.h> bool search(int value,...


1

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. This pset is, among other things, about learning to build an executable program from multiple source files and using the concept of a makefile. I'll refer ...


1

One of the lessons of this pset is how to build an executable from multiple source files using a makefile. The link error is happening because you are trying to make helpers. Because there are no instructions in the makefile on how to compile and link helpers, it tries to use default rules. The default rule says to create an executable based on the name of ...


1

Asked and answered in comments. Except for a minor flaw, the search code appears correct. It should be finding 127. More likely, there's a problem with the code that loads the numbers in the array. Try working with a smaller data set, maybe 10 elements, and print out the array to see if it is loading correctly. Also, you should know that you will never ...


1

Turns out that I just needed to re-compile find.c. So, I guess if your code should work in theory and syntax is correct, recompile what your working on and see if that works.


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