Thread: initializing 2d strings

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    37

    initializing 2d strings

    If I have class [5][20], how would I initialize it to have Boss, Manager, sales, ect on class[0][], class[1][] ..... respectively.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you write and post some code, we can help guide you through whatever problems you are seeing.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    http://cboard.cprogramming.com/showthread.php?t=98576

    On that post I have done the input thing correctly, sorting function is bad.

  4. #4
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Quote Originally Posted by Fox101 View Post
    If I have class [5][20]
    Is it a character array ? C does not have classes. It has structs.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    37
    Oh sorry, yes it is a character array, class is just the name of it.

    From your example, it looks like a user input, I want to go ahead and initialize the string to 5 different words.

    char class[5][20]={ }. What goes in the brackets?
    Last edited by Fox101; 02-05-2008 at 08:52 AM.

  6. #6
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Quote Originally Posted by Fox101 View Post

    Code:
    char class[5][20]={ }.
    What goes in the brackets?
    I am a beginner. I don't know what goes into the brackets. That's why I used a temp string and loops to access each element and put the characters in them

    I found what you are looking for:
    http://www.learncpp.com/cpp-tutorial...sional-arrays/
    Last edited by abh!shek; 02-05-2008 at 09:37 AM.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The syntax would be:
    Code:
    char class[5][20] = { "String1", "String2", etc };
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pls help:: function initializing for 2d array
    By ypramesh in forum C Programming
    Replies: 3
    Last Post: 03-29-2006, 03:35 PM
  2. 2d array of strings
    By localrob in forum C Programming
    Replies: 6
    Last Post: 08-23-2004, 02:49 PM
  3. Storing strings in 2d char arrays problem
    By rainmanddw in forum C++ Programming
    Replies: 5
    Last Post: 10-22-2003, 05:41 PM
  4. Initializing strings
    By The_Nymph in forum C Programming
    Replies: 1
    Last Post: 04-30-2002, 01:01 PM
  5. Initializing Strings
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-22-2002, 03:59 PM