Skip to content

Instantly share code, notes, and snippets.

@alyx
Created October 9, 2011 23:11
Show Gist options
  • Save alyx/1274343 to your computer and use it in GitHub Desktop.
Save alyx/1274343 to your computer and use it in GitHub Desktop.
tokenizer with memory asplosion
/* Sigyn - A reasonably sane IRC bot.
* Copyright (c) Alexandria Wolcott <alyx@malkier.net>
* Released under the BSD license.
*/
#include "sigyn.h"
int tokenize(char *message, char **parv)
{
int i;
char *token, *save;
i = 0;
save = strdup(message);
while ((i <= MAXPARC) && (token = strtok_r(NULL, " ", &save)) &&
(token != NULL))
{
printf("%d\n", i);
parv[i] = token;
i++;
if ((strlen(save)) < 1)
break;
}
if ((i > MAXPARC) && (save != NULL))
parv[i] = save;
if (parv[i] == NULL)
i--;
free(save);
return i;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment