Jump to content

a little problem with char array

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
worried_student

worried_student

    Newbie

  • Members
  • PipPip
  • 11 posts
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;

#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
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
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Another problem you have is the while condition will ALWAYS return true. Instead of using || to connect your options, use &&.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog