initializing 2d strings

This is a discussion on initializing 2d strings within the C Programming forums, part of the General Programming Boards category; If I have class [5][20], how would I initialize it to have Boss, Manager, sales, ect on class[0][], class[1][] ..... ...

  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
    Word Sort

    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 07: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 08:37 AM.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

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, 02: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

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