Thread: Array of words(strings)- please help!

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    1

    Array of words(strings)- please help!

    Hi!

    I want to create a simple program of arranging words in column. I found that this is like array. I know array of characters whereby you define type as char, whereby array elements are characters, now how to declare array of words so that array elements are words?

    thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can use a 2D array of characters. ( char foo[ rows ][ cols ] )
    You can use an array of pointers-to-char. ( char *foo[ SIZE ] )
    You can use a pointer-to-pointer-to-char. ( char **foo )

    You will have to use some dynamic memory allocation for the last two. You have to supply both sizes for the first one. And, since it turns out I somehow ended up on the C++ forum, you can use the actual string class.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    18
    Depends what you want to do with it, but the easiest thing it to use an STL vector of strings.

    std::vector<string> myVev.

    Then you can add, remove, sort or whatever else you might want to do.

  4. #4
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Are there that many of us?
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  5. #5
    Registered User
    Join Date
    May 2010
    Posts
    18
    Quote Originally Posted by CodeMonkey View Post
    Are there that many of us?


    I gather an infinite number of us, given an infinite number of compilers could write a half-decent "Hello world" program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multidimensional Array Addressing
    By BlackOps in forum C Programming
    Replies: 11
    Last Post: 07-21-2009, 09:26 PM
  2. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM