I liked doing this, it might be what you need. I did not test it extensively, but passed a simple test.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int
main(void)
{
char string[] = "12 13 14 16";
char *current;
char *next;
int done;
current = string;
done = 0;
while (done == 0)
{
next = strchr(current, ' ');
if (next == NULL)
next = strchr(current, '\0');
done = (current[0] == '\0');
if ((next != current) && (done == 0))
{
next[0] = '\0';
printf("--%s--\n", current);
next[0] = ' ';
current = next + 1;
}
else if (*next++ == ' ')
{
int spaces;
int count;
spaces = 1;
count = 1;
while (isspace((unsigned char) *next) != 0)
{
next++;
if (spaces % 2 == 0)
count += 1;
spaces++;
}
if (spaces % 2 != 0)
return -1;
for (int i = 0 ; i < count ; ++i)
printf("--0--\n");
current = next;
}
}
return 0;
}
source
share