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 6739195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:27:31+00:00 2026-05-26T11:27:31+00:00

im trying to perform an index search for string, it runs but the problem

  • 0

im trying to perform an index search for string, it runs but the problem is that it only prints out i[0] which is my first entry. if i lookup another entry it doesn’t work. Please help..
void clist(string fn[],string ln[], int size);

int search_list(const string fn[],const string ln[], int size, string find);

int main(){

    string search;

    cout << "This program searches a list .\n";

    const int total = 3;

    string fn[total];
    string ln[total];

    clist(fn,ln, total);

    cout << "Search contact:____  ";

    cin >> search;

    search_list(fn,ln, total, search);

  return 0;

}

void clist(string fn[],string ln[], int size){

    cout << "Enter " << size << " contact.\n";

    for (int index = 0; index < size; index++)
     cin >> fn[index] >> ln[index] ;

}

int search_list(const string fn[], const string ln[],int size, string search){

   for(int i=0;i<size;i++){

     if((fn[i] == search)&& (i < size)){

       cout<<"Result found "<<fn[i]<<" "<<ln[i]<<endl;

      break;

              }

    cout<<"no record found"<<endl;

     break;

    }

}
  • 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-26T11:27:32+00:00Added an answer on May 26, 2026 at 11:27 am

    You are making a loop and explicitly telling it to break out of it after the first iteration. Try writting it like this:

    bool found = false;
    for(int i=0;i<size;i++){
     if(fn[i] == search){ // No need to check for(i < size)
       found = true;
       cout<<"Result found "<<fn[i]<<" "<<ln[i]<<endl;
       break;
     }
    }
    
    if(!found)
      cout<<"no record found"<<endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to write a code that should allow me to search a string
I'm trying to perform an operation on each character of a string which is
Trying to perform a single boolean NOT operation, it appears that under MS SQL
I am trying to perform some unit testing on the iphone but for some
I am trying to implement a fulltext search on two columns which I created
I'm trying to perform a Median filter on an image in Java but it's
Trying to perform a very simple task here. I have an <ol> that contains
I have an if statement that I am trying to perform with JSTL. My
I've been trying to find the optimal solution to the following (interesting?) problem that
I am stuck trying to figure out how to do string hashing with linear

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.