Thread: Array problem - inavlid initializer

  1. #1
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    Array problem - inavlid initializer

    When I try to create a second array, I get the following error(s):
    Test.cpp: In function `int main()':
    Test.cpp:10: invalid initializer
    From the following code:
    Code:
    int main ( void )
    {
    	char * ArrayOne[2] = { "One - One", "One - Two" };
    	char * ArrayTwo[2] = ( "Two - One", "Two - Two" );
    	int Counter;
    	for ( Counter = 0; Counter < 2; Counter ++ )
    	{
         		cout << ArrayOne[Counter] << endl << ArrayTwo[Counter] << endl;
    	}
    	return 0;
    }
    Why?

    Moreover,
    What I am trying to do is:
    Code:
    int main ( void )
    {
    	char * ArrayOne[2] = { "C:\\Windows\\Network.txt", "C:\\Windows\\Printers.txt" };
    	char * ArrayTwo[2] = ( "C:\\Windows\\Desktop\\Netowkr.txt", "C:\\Windows\\Printers.txt" );
    	char * ArrayThree[2] = ( "Network documentation", "Printers documentation" );
    	int Counter;
    	for ( Counter = 0; Counter < 2; Counter ++ )
    	{
         		cout << FileCopy ( ArrayOne[Counter], ArrayTwo[Counter], ArrayThree[Counter] << endl;
    	}
    	return 0;
    }
    Or is there a better way?
    The world is waiting. I must leave you now.

  2. #2
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    wrong type of brace, they must be curly braces when initialising arrays.

    Code:
    char * ArrayOne[2] = { "One - One", "One - Two" };
    char * ArrayTwo[2] = { "Two - One", "Two - Two" };
    Probably a typo you didnt even see
    Couldn't think of anything interesting, cool or funny - sorry.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    3

    lol try this man

    Your code:

    ============================================
    int main ( void )
    {
    char * ArrayOne[2] = { "One - One", "One - Two" };
    char * ArrayTwo[2] = ( "Two - One", "Two - Two" );
    int Counter;
    for ( Counter = 0; Counter < 2; Counter ++ )
    {
    cout << ArrayOne[Counter] << endl << ArrayTwo[Counter] << endl;
    }
    return 0;
    }
    ============================================

    Fixed code:

    ============================================
    int main ( void )
    {
    char * ArrayOne[2] = { "One - One", "One - Two" };
    char * ArrayTwo[2] = { "Two - One", "Two - Two" };
    int Counter;
    for ( Counter = 0; Counter < 2; Counter ++ )
    {
    cout << ArrayOne[Counter] << endl << ArrayTwo[Counter] << endl;
    }
    return 0;
    }
    ============================================

    Should run fine now.
    Sometimes the problem is staring you right in your face.

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    *slaps forehead*
    Thanks guys.
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array problem
    By TomBoyRacer in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2007, 11:35 AM
  2. Replies: 6
    Last Post: 02-15-2005, 11:20 PM
  3. Problem Putting INTs Into a CHAR Array
    By cram in forum C++ Programming
    Replies: 13
    Last Post: 10-13-2004, 07:53 AM
  4. Merge sort please
    By vasanth in forum C Programming
    Replies: 2
    Last Post: 11-09-2003, 12:09 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM