Results 1 to 2 of 2

Thread: Convert Long to char array?

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    2

    Convert Long to char array?

    How to convert long to char[] ???
    Please help me! Thx!!

  2. #2
    Junior Member
    Join Date
    Jul 2012
    Posts
    2

    Re: Convert Long to char array?

    theme closed!

    Code :
    inline void L64toStr(long n, char* pStr)
    {
      int i = 0;
      int m;
      int len;
      char c;
      char s = '+';
     
      if( n < 0 )
      {
        s = '-';
        n = - n;
        pStr[0]='-';
        i++;
      }
     
      do
      {
        m = n % (long)10;
        pStr[i] = '0'+ m;
        n = n / (long)10;
        i++;
      }
      while(n != 0);
     
      if(s == '+')
      {
        len = i;
      }
      else /* s=='-' */
      {
        len = i-1;
        pStr++;
      }
     
      for(i=0; i<len/2; i++)
      {
        c = pStr[i];
        pStr[i]       = pStr[len-1-i];
        pStr[len-1-i] = c;
      }
      pStr[len] = 0;
     
      if(s == '-')
      {
        pStr--;
      }
    }
     
    inline long StrtoL64(char* pStr, long* pN)
    {
      int i;
      int len = sizeof(pStr);
      char s = pStr[0];
     
      *pN = 0;
     
      if(s == '-')
      {
        pStr++;
        len--;
      }
     
      for(i=0; i<len; i++)
      {
        if(pStr[i]>='0'  &&  pStr[i]<='9')
        {
          *pN = (*pN)*(long)10 + (pStr[i]-'0');
        }
        else
        {
          return 1;
        }
      }
     
      if(s == '-')
      {
        pStr--;
        (*pN) = - (*pN);
      }
     
      return 0;
    }

Similar Threads

  1. Replies: 2
    Last Post: 10-11-2011, 12:57 AM
  2. passing an array of char* to kernel function
    By naroqueen in forum OpenCL
    Replies: 15
    Last Post: 12-16-2010, 09:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •