Thread: 2d multidimensional array

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    2

    2d multidimensional array

    hey,
    I have a multidimensional array like this:
    Code:
    	char array[3][3] = {{'a','b','c'},{'d','e','f'},{'g','h','i'}};
    and have tried accessing it with:

    Code:
    printf("%s",array[1][1]);
    but it does not print out the value which is in that position, anyone able to tell me how to print out any individual value in the array, i'm a newbie to c and have looked through quite a few topics and tutorials yet I still can't get this thing to work.

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Use %c instead of %s. The value at array[1][1] is a character, and not a null-terminated string. %s is for printing an array of chars that ends with a null character.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    2
    ah, thanks a lot, must've really got mixed up between the 2.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D array of threads?
    By shorinhio in forum C Programming
    Replies: 2
    Last Post: 01-04-2007, 04:02 PM
  2. Allocating a 2D Array Differently
    By pianorain in forum C++ Programming
    Replies: 13
    Last Post: 12-15-2005, 02:01 AM
  3. Multidimensional Array in a Structure
    By Night_Blade in forum C Programming
    Replies: 3
    Last Post: 04-04-2005, 08:14 PM
  4. Copying from one 2d array to another....with a twist
    By Zildjian in forum C++ Programming
    Replies: 2
    Last Post: 10-24-2004, 07:39 PM
  5. Replies: 6
    Last Post: 10-21-2003, 09:57 PM