Hi,
I have a array string such as a setCode:S= {W,P,A,Z}
I only manage to search the first element which is W , but not for others ( it will say not found if i search for P, for instance), here is my code for searching part:
whats wrong with my code?
Code:cout <<"\nWhich element?: "; cin >>which; if((Search(&a[0], size, which)==true)) { cout <<which<<" is in S ."<<endl; } else { cout <<which <<" is not in S."<<endl; } break;
ThanksCode:bool Search(char *a, int size, char *which) // Search element { Ptr c =&which[0]; Ptr b= &a[0]; for (int i=0;i <size;i++) { if (b[i]==*c) { return true; // true if found } else { return false; // not Found element. } } }![]()



LinkBack URL
About LinkBacks




