Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 762815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:27:20+00:00 2026-05-14T16:27:20+00:00

I updated my main and sequetialSearch and now it crashes when it runs. It

  • 0

I updated my main and sequetialSearch and now it crashes when it runs. It compiles okay, but then crashes.

main.c

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include "percentage.h"
#include "sequentialSearch.h"

#define searchAmount 100

int main(int argc, char *argv[])
{
  int numbers[100];
  int searches[searchAmount];
  int testAmounts[searchAmount];
  int i;
  int where;
  int searchSuccess;
  int searchUnsuccess;
  int percent;
  int looker;
  int sum;
  int average;

  srand(time(NULL));
  for (i = 0; i < 100; i++){
      numbers[i] = rand() % 200;
  }
  for (i = 0; i < searchAmount; i++){
      searches[i] = rand() % 200;
  }

  searchUnsuccess = 0;
  searchSuccess = 0;
  sum = 0;

  for(i = 0; i < searchAmount; i++){
        if(seqSearch(numbers, 100, searches[i], &where, &looker)){
              searchSuccess++;
              testAmounts[i] = looker;

        }else{
              searchUnsuccess++;
              testAmounts[i] = looker;
        }
  }
  for(i = 0; i < searchAmount; i++){
        sum = sum + testAmounts[i];
  }

  average = sum / searchAmount;

  percent = percentRate(searchSuccess, searchAmount);
  printf("Total number of searches: %d\n", searchAmount);
  printf("Total successful searches: %d\n", searchSuccess);
  printf("Success Rate: %d%%\n", percent);
  printf("Total number of tests ran: %d\n", average);
  system("PAUSE");  
  return 0;
}

sequentialSearch.h

bool seqSearch (int list[], int last, int target, int* locn, int* looker){

     *looker = 0;
     while(*looker < last && target != list[*looker]){
                  *looker++;
     }

     *locn = *looker;
     return(target == list[*looker]);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T16:27:21+00:00Added an answer on May 14, 2026 at 4:27 pm

    Pass looker in by reference, so that you can access its value from the caller.

    int looker;
    
    ...
    
    for(i = 0; i < searchAmount; i++){
          if(seqSearch(numbers, 100, searches[i], &where, &looker)){
                searches[i] += looker;
                searchSuccess++;       
          }else{
                searchUnsuccess++;
          }
    }
    
    
    bool seqSearch (int list[], int last, int target, int* locn, int *looker){
         *looker = 0;
         while(*looker < last && target != list[*looker]){
                      (*looker)++;
         }
    
         *locn = *looker;
         return(target == list[*looker]);
    }
    

    By the way, you may wish to reconsider defining functions in your header file; this could cause problems with duplicate symbol when linking if you have more than one c file including this file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

correction it works now thanks everyone. Okay so now I have updated my main
Here is my console: irb(main):048:0> Time.now => 2011-04-13 00:51:50 +0200 <c => (@stats[5] ==
Updated below . The following is the entire code I have in my main.cpp:
My code is simply as this: UPDATED : #include <iostream> #include <fstream> using namespace
OK i asked this yesturday but i updated it with more detail as to
I have a timestamp which updates when the row is updated in my main
I have my main depotactivity where he sets integer value to a textview, now
UPDATE SOLVED I updated to Haskell Platform 2011.2.0.1 and GHC 7.0.3 and now it
Updated: This is a re-write from my original question (or lack of), the main
We have two applications. Main.exe - which is the main application being updated Update.exe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.