2d multidimensional array

This is a discussion on 2d multidimensional array within the C Programming forums, part of the General Programming Boards category; 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: ...

  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
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    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, 09: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, 08:39 PM
  5. Replies: 6
    Last Post: 10-21-2003, 10:57 PM

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