5 votes
Accepted

PSET3 LINEAR SEARCH

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 (...
user avatar
  • 17.4k
4 votes
Accepted

Pset3 Linear Search (control may reach end of non-void function)

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 "...
user avatar
  • 1,415
4 votes
Accepted

linear search not finding the needle

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 ...
user avatar
  • 3,326
2 votes
Accepted

Pset3 linear search. Please help me!

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 < ...
user avatar
  • 7,326
1 vote

Pset3 Linear Search (control may reach end of non-void function)

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 ...
user avatar
  • 171
1 vote

pset3 linear search not working

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 ...
user avatar
  • 64.1k
1 vote
Accepted

Caesar: Validating the key - stuck

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' ...
user avatar
  • 1,561
1 vote
Accepted

Linear find function always finding needle in hay stack and generating multiple numbers

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]= ". ...
user avatar
  • 64.1k
1 vote
Accepted

How to create an input for the search function?

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. ...
user avatar
  • 5,172
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....
user avatar
  • 64.1k
1 vote
Accepted

Why am I generating the following errors with this code if it says it's compiled correctly?

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 ...
user avatar
  • 64.1k
1 vote

Cannot find the needle 127 in the haystack of 1000 random numbers using linear search . Any ideas on what I may have done wrong?

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. ...
user avatar
  • 64.1k
1 vote
Accepted

Linear Search not working

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.
user avatar

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