Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#include <string.h>
/* Useful helper function */
const char* SkipToken(const char* str)
{
const char* p;
if (!str)
return 0;
while (*str == ' ')
++str;
if (*str == 0)
return 0;
p = strchr(str,' ');
return p?p:str + strlen(str);
}
/* Nth from Zero (it's C;); toksz <= 0 - no size check.
* Returns (almost useless) pointer to str (not to tok)
* or NULL if no such token...
*/
const char* GetNthToken(const char* str, int n, char* tok, int toksz)
{
int len;
const char* q;
const char* p = str;
while (n-->0)
p = SkipToken(p);
if (p)
{
while (*p == ' ')
++p;
if (*p == 0)
return 0;
if (!tok)
return p;
q = strchr(p,' ');
len = (q?q-p:strlen(p));
if (toksz <= 0 || len < toksz)
{
memmove(tok,p,len);
tok[len] = 0;
}
else
tok[0] = 0;
}
return p;
}