how to find size of unsigned char* ??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chetanhl
    New Member
    • Mar 2008
    • 8

    how to find size of unsigned char* ??

    Hey guyz if i wanna know how to find size of unsigned char*?

    void func1(unsigned char* str)
    {
    int a;
    a=??
    ////////////////now how to store size of str in a????


    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Either count the characters in str up to, but not including the \0, or pick up a C book and read up on the C library string functions.

    I'll bet there's one in there that will do exactly what you want.

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      You can use the sizeof() operator, but that will return the size of the actual pointer. If you are using the unsigned char* to point to a character array, you cannot use sizeof(). You can use strlen(), which counts the number of characters before the terminating '\0' character (which you should make sure is present before using any built-in functions like this), or you can use an extra int parameter and pass in the size when the function is called.

      Comment

      Working...