Thread: Comparing Character Arrays problem...

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    10

    Comparing Character Arrays problem...

    Hi
    Started c++ at uni (doing games programming) 5 weeks ago....its way tougher than i expected !!!

    Anyway....been on with this for ages and i cant get it to work....i have 2 names stored in a character array, and the user inputs into the aryInput array and i need it to verify that what has been entered is in the aryLoginName array....my problem is that if John is input, it outputs correctly, if Steve is entered it says invalid name...so it doesnt seem to be looping (?)....let me know if i havent explained it clearly....heads in a spin after working on the thing for hours...thanks!:

    Code:
    void login()
    {
    	char aryInput[10];
    	char aryLoginName [2] [10] =    {	"John",
                                                                                   "Steve",
                                                                     };
    
    
    		cout << "Please enter a valid name> ";
    		cin >> aryInput;
    		
    		for(int k = 0; k < 2; k++) //  names
    		{
    			int temp = strcmp( aryInput, aryLoginName[k]);
    
    			if( temp == 0)
    			{
    				cout << "You entered the correct name" << endl;
    				break;
    			}else cout << "Invalid name";
    			break;
    		}
    }
    Last edited by newy100; 11-16-2003 at 07:35 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 06-11-2009, 11:27 AM
  2. Manipulating Character arrays in functions.
    By kbro3 in forum C++ Programming
    Replies: 11
    Last Post: 08-16-2008, 02:24 AM
  3. Comparing elements of character pointer arrays
    By axe in forum C Programming
    Replies: 2
    Last Post: 11-14-2007, 12:20 AM
  4. Just a quick question about character arrays
    By Welshy in forum C Programming
    Replies: 3
    Last Post: 04-03-2006, 07:20 AM
  5. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM