/* strtok example */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main ()
{
	char str[] ="BLA BLA2 BLA3";
	char * pch;
	printf ("Splitting string \"%s\" into tokens:\n",str);
	pch = strtok (str," ");
	while (pch != NULL)
	{
	printf ("%s\n", pch);
	pch = strtok (NULL, " ");
	}
	
	char* strArray[50]; /* up-to 50 words can be stored */
	char str2[] = " Sample string!";
	char* p;
	int i = 0;

	p = strtok(str2, " ,.?!");
	while (p)
	{
		strArray[i] = malloc(strlen(p) + 1);
		strcpy(strArray[i++], p);
		printf("Extracted string part to element %i: %s\n", i, p);
		p = strtok(NULL, " ,.?!");
	}
	
	int j;
	for (j = i + 1; j <= 50; j++) {
		/* Initialize the rest. */
		printf("Finishing init of element %i\n", j);
		strArray[i] = malloc(1);
		//strcpy(strArray[i], NULL);
	}

	for (i = 0; i < 50; i++)
	{
		if (strArray[i]) { /* check for null data */
			printf("String part, element %i: %s\n", i, strArray[i]);
		}
	}
	
	return 0;
}