length of a string

Started by
4 comments, last by hello_there 20 years, 4 months ago
Say you have a function something like this void Func(char * File) How would you get the length of File.
____________________________________________________________How could hell be worse?
Advertisement
If you''ve null-terminated the char*, you can loop through for-style, and keep a counter, terminating the loop when you hit null.
Assuming a C-style null-terminated string:
strlen(File);
say i passed "Name" to the function would that be a NULL terminated string.
____________________________________________________________How could hell be worse?
Depends on the language, and how you''re actually calling it.

For example (valid in C, invalid in C++):
char name[4] = "Name"; /* No room for terminating null */Func(name); 

This would be non-null terminated.

However, just calling Func("Name"); should give you a null-terminated string in both C and C++.
cool got it working thanks
____________________________________________________________How could hell be worse?

This topic is closed to new replies.

Advertisement