creating an array of strings

This is a discussion on creating an array of strings within the C++ Programming forums, part of the General Programming Boards category; juz 1 quick qns, how do u create an array of strings?? Code: char *hostarray= "Cmc-01 Cmc-02 Cmc-03 Cmc-04"; //and ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    114

    creating an array of strings

    juz 1 quick qns,
    how do u create an array of strings??

    Code:
    char *hostarray= "Cmc-01 Cmc-02 Cmc-03 Cmc-04"; 
    //and test it by doing this
    MessageBox(hwnd,  hostarray[2] , "arrarytest", MB_OK);
    i am hoping this gives me hostarray[0] = "Cmc-01" , hostarray[1]= "Cmc-02" but it doesnt work



    kept getting the error

    "c:\program files\microsoft visual studio\projects\aaclient\array.h(56) : error C2664: 'MessageBoxA' : cannot convert parameter 2 from 'char' to 'const char *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    Error executing cl.exe."

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    Do this
    Code:
    char *hostarray[] = {
      "Cmc-01",
      "Cmc-02",
      "Cmc-03",
      "Cmc-04"
    };
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a menu that reads input via an array?
    By Nalif in forum C Programming
    Replies: 6
    Last Post: 09-29-2006, 09:21 PM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 08:51 AM
  3. Passing an Array of Strings from VB to a C DLL
    By mr_nice! in forum Windows Programming
    Replies: 9
    Last Post: 03-08-2005, 05:16 AM
  4. remove strings from array
    By ipe in forum C Programming
    Replies: 2
    Last Post: 01-12-2003, 03:53 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21