below are a part of my code for my program
it compiles with no error
but it does not work properly
i am really not good at handling char array and pointers, and do not understand very well. I need the program let user can input command by keyboard and my program would distinguish commands
=====
int main(){
int a;
BST_node* b;
char command[30];
char temp[30];
Contact c;
BST book;
do{
cout << "Please input command:";
cin >> command[30];
while (command!="insert" || command!="remove" || command!= "show" || command!="list" || command!="total" || command!="exit"){
cout<<endl;
cout << "Invalid command";
cin>>command[30];
}
cout<<endl;
if (command=="insert"){
cout<<"Please enter the name for the new contact:";
cin>>temp;
a little problem with char array
Started by worried_student, Nov 22 2007 05:53 PM
2 replies to this topic
#1
Posted 22 November 2007 - 05:53 PM
|
|
|
#2
Posted 22 November 2007 - 10:06 PM
You need to use the function, strcmp, for comparing your array with another string. Another alternative is to use std::string, but if I got you right, you need to work with char arrays? If that's right, then stick to the comparing function I first told you about.
#3
Posted 23 November 2007 - 08:18 AM
Another problem you have is the while condition will ALWAYS return true. Instead of using || to connect your options, use &&.


Sign In
Create Account


Back to top









