#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    3
    Rep Power
    0

    Question A constant array of strings


    It has been a little while since I touched C code, and I am trying to set up a constant array of strings. I thought that this would work:
    Code:
    const char* pctostr[2] = {"Ok", "End"};
    But it keeps giving me a "excess elements in aggregate initializer" error. Am I wrong in thinking it is possible to do this?

    -Ben
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    It compiled and ran find on my Win2K VC++6 box. Try leaving empty braces, the compiler will figure out how many elements are in the array.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    3
    Rep Power
    0
    Ah, that made it work. Thanks a lot mitakeet!

    Actually, I just now figured out what I was doing. I actually had the last element of a size two enum in the string, but to simplify things I put a constant there in the post, fixing the problem :)

    What happened is that enum's are 0 based, so actually I was only making the dimension '1' when I wanted to make it '2'.

    Sorry about that. Thanks again for the reply

IMN logo majestic logo threadwatch logo seochat tools logo