How to put a string in a 2 dimensional character array?

This is a discussion on How to put a string in a 2 dimensional character array? within the C Programming forums, part of the General Programming Boards category; how can you put a string into the 2 dimensional character array? lets say you have Code: char array1[10][10]; char ...

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    8

    Unhappy How to put a string in a 2 dimensional character array?

    how can you put a string into the 2 dimensional character array?

    lets say you have

    Code:
    char array1[10][10];
    char array2[10] = {"my array"};
    how do you put the value of "array2" in "array1" ??

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Code:
    char array1[10][10];
    // array1 has ten members, 0-9.  there is no array1[10], so...
    strcpy(array[9],"myarray");
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    8
    Quote Originally Posted by MK27 View Post
    Code:
    char array1[10][10];
    // array1 has ten members, 0-9.  there is no array1[10], so...
    strcpy(array[9],"myarray");

    Thank you so much,, You solved my problem... hehehe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 10:11 AM
  2. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 10:19 AM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. two dimensional character array
    By feuerraeder in forum C Programming
    Replies: 4
    Last Post: 11-22-2002, 08:59 AM

Tags for this Thread


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