Ejemplo n.º 1
0
static int get_tokens(const char str[MAX_REQ], char tok[MAX_TOK][MAX_TOKLEN], int (*test_delim)(char))
{
  int i     = 0;
  int token = 0;
  int index = 0;

  while (str[i] && token < MAX_TOK) 
    {
      /* strip spaces */
      while (str[i] && test_delim(str[i])) {
	i++;
      }

      /* copy token */
      index = 0;
      while (str[i] && !test_delim(str[i]) && index < MAX_TOKLEN) 
	{
	  tok[token][index++] = str[i++];
	}

      /* null terminate token */
      if (index)
	{
	  tok[token++][index] = '\0';
	}
    }
  return token;
}
Ejemplo n.º 2
0
int
get_tokens(const char *str, char tok[MAX_TOK][MAX_TOKLEN], int (*test_delim)(char)) {
    int i = 0;
    int token = 0;
    int index = 0;

    while (str[i] && token < MAX_TOK) {
        /* strip spaces */
        while (str[i] && test_delim(str[i])) {
            i++;
        }

        index = 0;
        while (str[i] && !test_delim(str[i]) && index < MAX_TOKLEN) {
            tok[token][index++] = str[i++];
        }
        tok[token++][index] = '\0';
    }
    return token;
}