Thread: Array and string

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    10

    Smile Array and string

    Hi,

    Let's say i have a 2d array that is 25x25 for example


    Myarray[25][25]


    And I have a text in a string for example char mystring[15] = "thisismystring"

    How can i save the string into the array, starting from the space i choose, lets say i want it to begin at [4][5] ... What's the method used to do that? I'm just learning

    Also, how would i do that vertically?

    Thanks

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    For cstring[4][5]

    You should probably create a cstring with the proper number of spaces then strcat() the two strings together. If you don't put something known in the first part of you cstring you won't know what is there. It could have the terminating character at 4[0] then your cstring will appear to be blank.

    For cstring[i][0]

    You just use the proper value of i and then write your cstring.

    Jim

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    This sounds somewhat like a homework question. Please show us your code and tell us where you're getting stuck rather than just asking for a complete answer.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Arrays of pointers...
    By Programmer_P in forum C++ Programming
    Replies: 60
    Last Post: 05-24-2010, 09:58 AM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM