question about arrays

This is a discussion on question about arrays within the C Programming forums, part of the General Programming Boards category; hello, how can i print an array of strings? how do i make this array thank you....

  1. #1
    Unregistered
    Guest

    Question question about arrays

    hello,
    how can i print an array of strings? how do i make this array

    thank you.

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    An array of strings can be done like so
    Code:
    #include <stdio.h> 
    
    int main(void) 
    
    { 
        char array[][7] = { {"First"},
                            {"Second"},
                            {"Third"},
                            {"Fourth"} };
    
    	int x;
    
    	for(x=0; x<4; x++)
    		printf("\n%s", array[x]);
    
    	return 0;   
    }
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Unregistered
    Guest

    Talking Using a pointer

    the other way of doing what Mr. C_Coder has provided is the following:
    ---------------------------------------------------------------------------

    #include <stdio.h>

    int main(void)

    {
    char *array[] = { "First",
    "Second",
    "Third",
    "Fourth"};

    int x;

    for(x=0; x<4; x++)
    printf("\n%s", array[x]);

    return 0;
    }

  4. #4
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    the latter solution is more space-efficient.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about arrays.
    By Kelvie in forum C++ Programming
    Replies: 3
    Last Post: 09-17-2007, 06:32 AM
  2. A question concerning character arrays
    By ellipses in forum C Programming
    Replies: 3
    Last Post: 03-08-2005, 08:24 PM
  3. Replies: 6
    Last Post: 04-26-2004, 11:02 PM
  4. Question about char arrays
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 10-21-2003, 01:44 AM
  5. Question about arrays?? PLease read..
    By foofoo in forum C Programming
    Replies: 3
    Last Post: 06-24-2002, 03:40 PM

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