C-Array Of Strings Manipulation Explained
How to declare array of strings?
1. char stringarray[10][10]
2. char *stringarray[10]
I prefer second one for declaration of array of strings,
How to Manipulate Array of strings?
Ex:
Copy some values in this array,
char *tmp=NULL;
tmp="test";
stringarray[0]= malloc(strlen(tmp)+1);
if(stringarray[0] != NULL)
strcpy(stringarray[0],tmp);
The value from tmp variable is copied to zeroth element of string array.
check out using printf
printf("string array element=%s",stringarray[0]);
Like this one can Do other manipulation on array of strings.
How to declare array of strings?
1. char stringarray[10][10]
2. char *stringarray[10]
I prefer second one for declaration of array of strings,
How to Manipulate Array of strings?
Ex:
Copy some values in this array,
char *tmp=NULL;
tmp="test";
stringarray[0]= malloc(strlen(tmp)+1);
if(stringarray[0] != NULL)
strcpy(stringarray[0],tmp);
The value from tmp variable is copied to zeroth element of string array.
check out using printf
printf("string array element=%s",stringarray[0]);
Like this one can Do other manipulation on array of strings.
Comments