Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. char* _simple_strtok(const char* pc, char delimeter)
  2. {
  3.    static unsigned char* pOldString;
  4.    static unsigned char* pString;
  5.    static unsigned char* pWorkingString;
  6.    static int iPosition;
  7.    static int iOldPosition;
  8.    char* cReturnCode = 0;
  9.  
  10.    if (!pc)
  11.    {
  12.       //if pc equals NULL use the old string from before
  13.       pString = pOldString;
  14.    }
  15.    else if (pc)
  16.    {
  17.       pString = pc;
  18.    }
  19.  
  20.    pWorkingString = pString;
  21.  
  22.    while ((pString[iPosition]!= '\0') && (pString[iPosition] != ';'))
  23.    {
  24.       iPosition++;
  25.    }
  26.  
  27.    cReturnCode = (char*)calloc((iPosition - iOldPosition) + 1, sizeof(char));
  28.    int i = sizeof(cReturnCode);
  29.    //memcpy(cReturnCode, pString + iOldPosition, iPosition);
  30.    strncpy(cReturnCode, pString + iOldPosition, iPosition);
  31.  
  32.    iOldPosition = iPosition+1;
  33.    pOldString = pString + (iPosition - iOldPosition);
  34.  
  35.    return cReturnCode;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement