Help printing out two arrays

This is a discussion on Help printing out two arrays within the C Programming forums, part of the General Programming Boards category; //I want to know to print out two array colums. For example, char list_ch[][2]={'1','a', '2','b', '3', 'c', '4', 'd', '5', ...

  1. #1
    Unregistered
    Guest

    Help printing out two arrays

    //I want to know to print out two array colums. For example,

    char list_ch[][2]={'1','a',
    '2','b',
    '3', 'c',
    '4', 'd',
    '5', 'e',
    '6', 'f'};

    //I want to print them out in two colums

    //please tell me the easiest way, I am just beginning to C.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    int i;
    for(i=0;i<6;i++)
    printf("%c\t\t%c",list_ch[i][0],list_ch[i][1]);
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Unregistered
    Guest
    What does this mean?
    list_ch[i][0],list_ch[i][1]);

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    "i" is the loop variable that allows you to access the values in the array.

    Like:


    Code:
    array[10];
    int k;
    
    
    for(k = 0; k < 10; k++)
    {
    array[k] = k;   //<--"k" is at  "4" on the fifth go-around
    //....................// So if I assign the VALUE of "k" to the value in the
    //...................// array, then array[4] ==4 !
    }
    
    
    for(k = 0; k < 10; k++)
    {
    printf("%i", array[k]);   // <--See for yourself
    }
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  5. #5
    Unregistered
    Guest

    Arrays

    Ok I understand that the loops, but I mean what do the list_ch[i][0],list_ch[i][1]); mean you know how it has a zero right next to the "i".

  6. #6
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    In C the array indexing starts from 0.
    FOr eg.,
    if you declare
    int a[10];
    since the array starts from 0 the elements are
    a[0],..............,a[9]any code containing a[10] might crash.
    but If I am not mistaken it is legal to assign a pointer one past the end of a array
    int a[10];
    int p;p=a+10; /*probably legal*/
    *p;/*illegal*/

  7. #7
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    I meant
    int a[10];
    int *p;
    p=a+10;/*probably legal*/
    *p;/*illegal*/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seperating initialising and printing of arrays into functions
    By Tom Bombadil in forum C Programming
    Replies: 1
    Last Post: 03-11-2009, 11:47 AM
  2. Printing arrays to curses screen
    By trev456 in forum C++ Programming
    Replies: 4
    Last Post: 05-07-2007, 12:46 AM
  3. printing arrays with concatenation
    By derek23 in forum C Programming
    Replies: 1
    Last Post: 07-17-2005, 03:02 AM
  4. New to C, printing arrays
    By kidglove14 in forum C Programming
    Replies: 1
    Last Post: 02-26-2002, 02:32 PM
  5. Printing back arrays
    By Intimd8r in forum C Programming
    Replies: 3
    Last Post: 10-01-2001, 12:50 PM

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