Okay, I have a problem. In this code, after the first call to strtok, the variable becomes "developer" when it was originally "developer;developer 0;developer". I would have expected it to become "developer 0;developer" after the first call..

void Con_Execute(char *text)
{
    char *pch;
    char string[10240];

    strcpy(string,text);

    if(!strstr(string,";"))
    {
        Cmd_ExecuteString(string);
        return;
    }

    pch = strtok(string,";");
    while(pch)
    {
        Cmd_ExecuteString(string);
        pch = strtok(NULL,";");
    }
}

Now I think I see what you're question is:

Try running this:

#include <stdio.h>
#include <string.h>

int main() {
  int i, unique; 
  char str[]="developer,developer0,developer";
  char *pstr;
  printf("\n\n original string: %s \n", str);
  pstr = strtok(str, ",");
  printf("\n  pointer: %s \n", pstr);
  printf("\n string[]: %s \n", str);


  while(1) {
    pstr = strtok(NULL, ",");
    if(!pstr)
      break;
    printf("\n  pointer: %s \n", pstr);
    printf("\n string[]: %s \n", str);
  }
  printf("\nFinal string prints as: %s \n", str);
  printf("\nBut the final string has visible char's of: \n");
  for(i=0;i<sizeof(str);i++)
    putchar(str[i]);
  
  printf("\n\n\t\t\t     press enter when ready");

  i = getchar(); ++i;
  return 0;
}

I don't understand, that's exactly what I did, but I only ever get the first 'developer' :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.