C-Strings

Strings

String library functions

stdlib.h string conversion functions

stdio.h string i/o functions

Common string.h string manipulation functions

Dynamically allocating space for strings and putting them in an array:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

void addstring(char **stringarray, char *newstring, int * numptr)
{   printf("allocating %lu bytes for %s\n",strlen(newstring)+1,newstring);
    stringarray[*numptr] = malloc(strlen(newstring)+1);
    strcpy(stringarray[(*numptr)++],newstring);
}

int main()
{
    int numstrings = 0;
    char *sarray[100];

    addstring(sarray, "hi", &numstrings);
    addstring(sarray, "ho", &numstrings);
    addstring(sarray, "wee", &numstrings);
    for (int i=0; i < numstrings; i++) {
       printf("%s\n",sarray[i]);
       // must also free the strings to prevent memory leaks
       free(sarray[i]);
    }
}

See also the Pointers & Dynamic Memory Allocation notes resource.