Questions tagged [linear-search]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
58 views

Please help debug linear search program in C

Could you please help me debug a linear search program I wrote in C? The do while loop seems to be executed only once without looping and, as a result, the program does not print the largest int as I ...
Yuya Ito's user avatar
1 vote
1 answer
56 views

How to create an input for the search function?

I am trying to test my search function by creating a separate function that takes an input [some integer] and then checks whether that integer fits within the given array [numbers 10-19]. I made the ...
Haim's user avatar
  • 185
0 votes
2 answers
168 views

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

This seems pretty simple, but I'm not sure what I'm doing wrong. Thanks in advance for helping! bool search(int value, int values[], int n) { if (n >= 0) { for (int i = 0; i <= n; i++...
Hello's user avatar
  • 3
0 votes
1 answer
968 views

PSET3 LINEAR SEARCH

Please help me with this: My code for linear search: // To check n is a positive int. if (n<0) { return false; } // To check if value can be found in values array. if values is found return ...
Malik's user avatar
  • 13
0 votes
1 answer
309 views

Pset3 linear search. Please help me!

I'm doing pset3 and I seem to have a functioning linear search. But I can't find my "needle" if it's in a higher array position than 331, which is where 127 is (I've copied the output of "generate" to ...
Alexander Lundskog's user avatar
0 votes
1 answer
77 views

Caesar: Validating the key - stuck

I am stuck with Caesar, validating the key. Before i use the atoi function, I want to check if argv consists of digits. I watched the linear search movie but is is to cryptic for me. I have to ...
Mark's user avatar
  • 7
0 votes
1 answer
88 views

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

I wanted to start simple with a linear search in the helper.c function: bool search(int value, int values[], int n) { // TODO: implement a searching algorithm for (int i = 0; value < n; i++) { ...
Haim's user avatar
  • 185
0 votes
1 answer
75 views

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

I just tried to compile this file(helpers.c), as a function implementation that is already included as a header for the main programme(find.c). I am not sure what else to do anymore, I have tried ...
Kgotso Koete's user avatar
0 votes
1 answer
21 views

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

The code compiles, and based off what I've seen in the linear search video, this should work. Tad bit confused why with this code below this error, I'm getting this error. In function `_start': (....
jayfeather31's user avatar
0 votes
1 answer
59 views

pset3 linear search not working

So I've started working on pset3 after a long break, I couldnt even start making a binary search function. Tried to do a linear search function but it doesnt seem to work when i run "./generate 1000 ...
Arda Cuce's user avatar
0 votes
1 answer
375 views

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

I'm having a bit of difficulty in compiling the helpers.c program. Specifically when I try to check the correctness of the program, it seems it cannot find the needle 127 in the haystack of 1000 ...
Dylan Savoury's user avatar
0 votes
1 answer
512 views

Linear Search not working

Alright, so, I'm not quite sure what's going wrong here, but maybe you people could help. My implementation of linear search in pset3 will return false no matter what (well, specifically I've only ...
Phoxxent's user avatar
0 votes
2 answers
53 views

I have written a linear searh algorithm. How do I test it to see that it works?

This is my linear search code. How do I test it to see if it works? /** * helpers.c * * Computer Science 50 * Problem Set 3 * * Helper functions for Problem Set 3. */ #include <cs50.h> ...
stephen Ong's user avatar
0 votes
1 answer
122 views

PSet 3 Helpers/Find Compile Error

I started changing "helpers.h" to implement a linear search. I have not changed generate.c or find.c. #include <cs50.h> bool search(int value, int values[], int n); { for(int i = 0; i < n;...
K. Rich's user avatar
  • 11
0 votes
1 answer
57 views

PSET 3 Linear Search Error

Keep getting the error of "control may reach end of non-void function" This is for the linear search, can someone please give me some help/tips into getting this error to go away? This is my code: ...
Faith Zellman's user avatar
0 votes
1 answer
40 views

search not compiling -

I want to just see if the search part of helpers.c works, but upon compiling, I get a really long error: this goes on for about 20 lines. Not sure what to do. I read through other posts, tried make ...
Richard Stein's user avatar
0 votes
1 answer
801 views

pset3 helpers.c linear search confusion

bool search(int value, int values[], int n) // TODO: implement a searching algorithm if (n >= 0) { for (int i = 0; i < n; i++) { if (values[i] == value) ...
hagan10's user avatar
0 votes
0 answers
103 views

Why isn't my linear search working correctly?

I cannot get my linear search programm to work and it seems to be a problem with the return of false if the needle is not found. My coding for the search is bool search(int value, int values[], int n)...
salim's user avatar
  • 1
0 votes
0 answers
91 views

My linear search can't find any values. Why?

Here's the code for my pset 3, which fails to find the '127' in the stack. Any hints will be massively appreciated: bool search(int value, int values[], int n) { for(int i = 0; i < n; i++) ...
mathmagician's user avatar
0 votes
2 answers
128 views

Pset3 - working on linear search

I'm currently working on adding the linear search and receive the following error when I try to compile... Also, when changing the code for helpers.c, is it necessary to compile that file or just ...
cignal's user avatar
  • 15
0 votes
0 answers
76 views

Control may reach end of non-void function [duplicate]

I have read the following and am still unable to answer my question: How to Fix “control may reach end of non-void function” and “No such file or directory” Errors? Error: control may reach end of ...
Roxanne's user avatar
  • 33
0 votes
1 answer
326 views

pset3 - Linear search wont work at all

So, I'm currently stuck on pset3. I'm doing the linear search coding on helpers.c but it doesn't seem to search for the needle in the hay stack. It is behaving quite weird. If i run ./generate 1000 ...
Pulkit Pandey's user avatar
0 votes
1 answer
812 views

linear search compilation error

I've updated search function in helpers.c with code below. I had to remove reference to helpers.h since that was causing even more errors. #include <cs50.h> // #include "helpers.h&...
Dauren Z's user avatar
0 votes
0 answers
114 views

what's wrong with my linear search?

I don't get this. I did a whole lot of debugging with gdb, and somehow move returns false automatically just after this simple search for the tile. int p=0,q=0; for(i=0;i<d ;i++) { for(j=0;j<...
Amrita's user avatar
  • 50
-1 votes
1 answer
235 views

linear search not finding the needle

I tried making find and then running ./generate 1000 50 | ./find 127 but it won't find the needle in the haystack. This is what I have for helpers.c: #include "cs50.h" #include "helpers.h" bool ...
Evan's user avatar
  • 25