Coder's Guild Mailing List

Problems with switch

Posted by Gazza on 2000-05-28

Hi all,below is a snipp of my switch statement which works ok,except that
the string that is being passed to strtok() changes,that is the number of
tokens vary,here is a typical string passed
buff[75]= ",0.37,2.754,33.05,5.7865,100000";
this produces 5 tokens,namely,buy,sell,high,low,vol, however,sometimes the
data has only the first 4 tokens within the passed string,how can i trap
this,and drop out of the swiich when this occurs,is the switch the right way
to do this,any help would be greatly appreciated
Many thanks: Cheers Gazza

t = strtok(buff,comma);
 while(t != NULL)
   {
    i++;
    switch(i)
      {
       case 1:
            strcpy(xt[0],t);
            test(xt[0]);
            printf("xx buy    %s",xt[0]);
            getchar();
            break;
       case 2:
            strcpy(xt[1],t);
            test(xt[1]);
            printf("xx sell   %s",xt[1]);
            getchar();
            break;
       case 3:
            strcpy(xt[2],t);
            test(xt[2]);
            printf("xx high   %s",xt[2]);
            getchar();
            break;
       case 4:
            strcpy(xt[3],t);
            test(xt[3]);
            printf("xx low    %s",xt[3]);
            getchar();
            break;
       case 5:
            strcpy(xt[4],t);
            printf("xx vol    %s",xt[4]);
            getchar();
            break;
       default:
            break;
       }
    t = strtok(NULL,comma);
    }