length of a string
Say you have a function something like this
void Func(char * File)
How would you get the length of File.
If you''ve null-terminated the char*, you can loop through for-style, and keep a counter, terminating the loop when you hit null.
Depends on the language, and how you''re actually calling it.
For example (valid in C, invalid in C++):
This would be non-null terminated.
However, just calling Func("Name"); should give you a null-terminated string in both C and C++.
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++.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement