static char array

This is a discussion on static char array within the C++ Programming forums, part of the General Programming Boards category; Hello I need a static string array in my program for instance: Code: char *day[7] = {"Sun", "Mon", "Tue", "Wed", ...

  1. #1
    l2u is offline
    Registered User
    Join Date
    May 2006

    static char array


    I need a static string array in my program for instance:

    char *day[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
    Is there any better/other way to do this in c++, or I have to do it the same as in c?

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Out of scope
    #include <string>
    std::string days[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
    ... or depending on how it's used
    enum days { SUN, MON, TUE, WED, THU, FRI, SAT };
    ... but of course that option also works in C, as well.
    Sent from my iPadŽ

  3. #3
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    char day[7][4]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
    I am not sure \0's are needed but I added them so there can be no problem with the code.
    Last edited by maxorator; 10-08-2006 at 07:03 AM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    They're not needed. On the contrary, you just created compile-time buffer overflows, and a good compiler would refuse to compile it.
    All the buzzt!

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  3. Sorting Linked Lists
    By DKING89 in forum C Programming
    Replies: 6
    Last Post: 04-09-2008, 07:36 AM
  4. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 12:18 AM
  5. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM

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