Use array of pointers for array of strings - C String

C examples for String:char array

Description

Use array of pointers for array of strings

Demo Code

#include <stdio.h>
#define SLEN 40//from   www.  j ava2 s  .  c o m
#define LIM 5
int main(void)
{
    const char *mytalents[LIM] = {
        "test",
        "test 2", 
        "test 3",
        "test 4",
        "test 5"
    };
    char yourtalents[LIM][SLEN] = {
        "test 6",
        "test 7", 
        "test 8",
        "test 9", 
        "test 10"
    };
    int i;
    
    printf ("%-36s  %-25s\n", "My Talents", "Your Talents");
    for (i = 0; i < LIM; i++)
        printf("%-36s  %-25s\n", mytalents[i], yourtalents[i]);
    printf("\nsizeof mytalents: %zd, sizeof yourtalents: %zd\n", sizeof(mytalents), sizeof(yourtalents));
    
    return 0;
}

Result


Related Tutorials