Thread: Sequential search- error?

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    12

    Sequential search- error?

    Hello guys. I am writing sequential search programm, i am not finished yet but already have error while trying to compile, what's the problem? Thank you very very very much for your help!!!!!!! =)
    error:
    In function 'seqSearch'
    syntax error before ')' token

    it is in first for loop
    Code:
    int seqSearch(int list[], int last, int target, int locat){
                int search;
                int numOfsearch=0;
                int found=0; 
                for(search =0; search < last && target != list[search])
                           search++;
                locat = search;
                if(target == list[search])
                          found = 1;
                else{
                    numOfsearch= search+1;
                    }
                printf("\n %d \n", numOfsearch);
                return found;
                     }
          
    int main()
    {
       int n=100;
       int list[n];
       int last = n-1;
       int target;
       int locat=0;
       int found=0;
       
       printf(" Please enter number that you whant to search for:\n");
       scanf("%d\n", &target);
     
       arrayfill(list, last);
       found=segSearch(list, last, target, locat);
       
     
      system("PAUSE"); 
      return 0;
    }
    Last edited by denisa; 12-05-2011 at 11:39 PM.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Like this...
    Code:
    int seqSearch(int list[], int last, int target)
         {
                int search;
                for(search =0; search < last; search++)
                  if ( target == list[search] )  
                        return search;      // found
    
                return -1; // not found
         }

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    12
    i got it
    Last edited by denisa; 12-05-2011 at 11:50 PM.

  4. #4
    Registered User
    Join Date
    Sep 2011
    Posts
    12
    thank you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What is sequential search?
    By Haakon in forum C Programming
    Replies: 14
    Last Post: 07-20-2011, 03:45 PM
  2. please help (sequential search)
    By thestrap in forum C Programming
    Replies: 2
    Last Post: 11-02-2007, 01:17 AM
  3. Storing random number in array(sequential search & bubble sort)
    By dukethacore in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2005, 08:28 AM
  4. Storing random number in array(sequential search & bubble sort)
    By dukethacore in forum C++ Programming
    Replies: 1
    Last Post: 07-20-2005, 07:23 AM
  5. Recursive sequential search
    By supaben34 in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2002, 11:06 AM