|
-
Feb 1st, 2003, 10:35 PM
#1
Thread Starter
Hyperactive Member
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.
-
Feb 8th, 2003, 06:27 PM
#2
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.
-
Feb 8th, 2003, 06:45 PM
#3
Thread Starter
Hyperactive Member
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.
-
Feb 8th, 2003, 07:18 PM
#4
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.
-
Feb 9th, 2003, 09:44 AM
#5
Frenzied Member
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.
-
Feb 10th, 2003, 05:42 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|