Results 1 to 6 of 6

Thread: Lstrlen Alternative

  1. #1

    Thread Starter
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394

    Exclamation Lstrlen Alternative

    Hi,

    Is there a function that determines string (or null-terminated memory block) size and returns DWORD or INT64?

    Or do I have to write my own?

    Thanks for help.
    VS.NET 2003

    Need to email me?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Where's the problem with size_t? It's the platform word lenght.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Hyperactive Member made_of_asp's Avatar
    Join Date
    Jul 2001
    Location
    123 Fake Street
    Posts
    394
    I don't know - I think size_t is a bit small.
    But lstrlen returns int

    I can't use CRT functions.

    Never mind I wrote my own function now.
    VS.NET 2003

    Need to email me?

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The maximum positive value for int is about 2 billion. Since every strlen, no matter which, simply checks character by character for a \0 any string that could break the int limit is unlikely to be held in memory.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    CB is correct - there is no need for it, although it's very simple.

    Code:
    DWORD mystrlen(char * src){
           DWORD len = 0;
           char *buf;
           for(buf=src;*buf; len++,buf++); 
           return len;
    }
    but I don't get why you need to do it.

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You don't even need the buf, you can directly write
    for(;*src; ++len,++src);
    and if you don't plan to use exotic compilers (probably not when programming for windows) you should write
    DWORD mystrlen(const char * src)
    for the sake of better design, or even better
    DWORD mystrlen(const TCHAR *src)
    or
    DWORD mystrlen(LPCTSTR src)
    to support UNICODE builds.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

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



Click Here to Expand Forum to Full Width