With this post I show you how to create an array of strings and how you can pass it to a function.

#define MAXROW 5
#define MAXCOL 50

int ChangeItem(char** listof,char index)
{
  sprintf(listof[index],"index passed is changed" );
  printf("\n\n++++++Item zero changed *********\n");

}
char TestArrayOfStrings()
{
    char listof[MAXROW][MAXCOL];//declare array of string
    char *p[MAXROW];//pointer to array of string
    int i;
    printf("++++++Print same array of strings *********\n");
    for (i=0;i<MAXROW;i++)
    {
        p[i]=listof[i];//prepare pointer
        sprintf(p[i],"Item %c",i+65);//same strings
        printf("%s\n",p[i]);//print original array of strings
    }


    ChangeItem(&p,3);
    printf("\n\n++++++Reprint array of strings *********\n");
    for (i=0;i<MAXROW;i++)
        printf("%s\n",p[i]);//reprint array of strings with first item changed

}

This is result:
arraystrings

another method, see also: Array Of Strings

Advertisements