![]() |
error in c++ progm
hello please solve this prob (LValue required)
void main() { int a=0; char *ptr[10]={" kanitkar","balagurushami","morishmano"}; char str[20]; clrscr(); cout<<"enter name to search\n"; cin>>str; for(a=0;a<3;a++) { if(!strcmp(str, *ptr[a])) { cout<<"book is found"<<endl; break; } ptr++; } if(a==3) cout<<"book not found"; getch(); } |
I'm new to C++, that shows in the console format right? And what does that code do if you'd share please? :)
|
I haven't done C++ in some time but your trying to compare a string to a table to know if the book is there or not.
I say your For loop should compare the result and return a value true or false by making a mask whit AND or OR fonction. It should return a 0 or 1 like a mask for bit. Then define the b has true of false and go to the if loop; if ( b = true ) {cout<<"book is found"<<endl; break;} Else {cout<<"book is found"<<endl; break;} your current table only has 3 choice, but if it get bigger you have to modify 3 line. This way you scan the whole table and return T or F. Modifying only 2 line. |
| All times are GMT. The time now is 02:28 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.