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.
Printable View
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.
Where's the problem with size_t? It's the platform word lenght.
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.
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.
CB is correct - there is no need for it, although it's very simple.
but I don't get why you need to do it.Code:
DWORD mystrlen(char * src){
DWORD len = 0;
char *buf;
for(buf=src;*buf; len++,buf++);
return len;
}
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.