Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please recognize that you are comingling C++ string (std::string) and the C library strcpy and strcmp functions. They are two different things. You probably need to look at some of the methods available under the std::string class (.c_str, =, ==),</p> <p>Here are a few comments, and suggestions,</p> <pre><code>void search (string sid[], //do you intend to pass a string sid, or an array of srings? string name[], //do you intend to pass a string name, or an array of strings? int No_of_data_input) { char id[100]; string input; char namename[100]; //comments ignored/removed //these two lines declare the function strcpy char * strcpy ( char * namename, const char * name ); char * strcpy ( char * id, const char * sid ); //do you intend to copy name and sid instead? //do you want: strcpy(namename, name[i].c_str() ); //do you want: strcpy(id, sid[i].c_str() ); //if so, you want to do this inside your loop on i, below, int sameName=0; int j=0; cout&lt;&lt;"enter id or name"; getline(cin,input); //you probably want: cin &gt;&gt; input; //do you intend to declare the function strcpy yet again? char * strcpy ( char * inputinput, const char * input ); //or do you intend to copy input to some char[]? //you probably want: strcpy( inputinput, input.c_str() ); //you probably want number of elements in sid[] or name[]? for(int i=0;i&lt;4;i++){ //you probably want sid[i] here if ((strcmp(inputinput,id[i])==0) || (strcmp(inputinput,name[i])==0)){ //you could rewrite this as: //if( (input == id[i]) || (input == name[i]) ){ sameName++; j=i; } //do us a favor } //make the ending braces clearer cout&lt;&lt;sameName; if (sameName==0) cout&lt;&lt;"No student found: "; else if (sameName==1) cout&lt;&lt;"student found: "&lt;&lt;name[j]&lt;&lt;endl&lt;&lt;id[j]; else if (sameName&gt;1) cout&lt;&lt;"More than one student found,please enter id"; } </code></pre> <p>Do you want (or need) to comingle std::string and strcpy, strcmp?</p> <p>Editing your code, you might want to just use std::string,</p> <pre><code>void search (string sid[], //do you intend to pass an array of srings? string name[], //do you intend to pass an array of strings? int count) { string input; int same=0; int j=0; cout&lt;&lt;"enter id or name"; cin &gt;&gt; input; //you probably want number of elements in sid[] or name[]? for(int i=0;i&lt;count;++i){ if( (input == sid[i]) || (input == name[i]) ){ ++same; j=i; } } cout&lt;&lt;"same: "&lt;&lt;same&lt;&lt;endl; if (same==0) cout&lt;&lt;"No student found: "&lt;&lt;endl; else if (same==1) cout&lt;&lt;"student found: "&lt;&lt;name[j]&lt;&lt;","&lt;&lt;id[j]&lt;&lt;endl; else if (same&gt;1) cout&lt;&lt;"More than one student found,please enter id"&lt;&lt;endl; } </code></pre> <p>Maybe you could use a vector of strings? Then you could use an iterator on the vector.</p> <p>You may have more success if you define a student record (containing sid and name), and pass a vector of student records. Then use an iterator over that vector -- read about vector and iterators.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload