Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-22-2007, 08:53 PM
worried_student worried_student is offline
Newbie
 
Join Date: Nov 2007
Posts: 11
Rep Power: 0
worried_student is on a distinguished road
Default a little problem with char array

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;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 11-23-2007, 01:06 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

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.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-23-2007, 11:18 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,418
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default

Another problem you have is the while condition will ALWAYS return true. Instead of using || to connect your options, use &&.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Programming is a branch of mathematics.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Usage of array structures to increment letter instances of text Yuriy M C and C++ 2 09-13-2007 11:49 AM
Visual Studio 2003 convert System::String to char array karateboy02 Managed C++ 0 07-27-2007 10:00 AM
Python 2D array question annannienann Python 3 04-23-2007 05:36 PM
C++ Array Problem dksmarte C and C++ 4 04-13-2007 12:52 AM


All times are GMT -5. The time now is 02:46 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads