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

/* 
   This function pulls a data element from a token delimited list 
   string - is the string to perform the operation on
   c - is the delimiter char ie; a coma or a space.
   token - is the token number to return ie; 0,1,2 etc.
*/


char *PullToken(char *string, int c, int token)
{
char	*RetTokenPtr;
char	RetToken[4096];
int	i=0;
int	s=0;
int	k=0;

RetToken[0] = 0;

while ( string[i] != 0 )
   {
   if ( s == token )
      {
      while (( string[i] != c ) && ( string[i] != 0 ) && ( i < 1024 ))
         {
         RetToken[k] = string[i];
//         printf("%c",string[i]);
         i++;
         k++;
         }
      RetToken[k] = 0;
      break;
      }
   if ( string[i] == c )
      {
      s++;
      }
   i++;
//   printf("\n -- %i --",i);
   }

RetTokenPtr = malloc(strlen(RetToken)+1);
strcpy(RetTokenPtr,RetToken);

return RetTokenPtr;
}
