Anything bad about using char [] in functions?

Started by
2 comments, last by johnnyBravo 20 years, 1 month ago
hi, for this function:

void myFunc(char name[])
{
   OutputDebugStringtheName(name);
}
is there any thing bad about putting the ''name'' as ''char name[]''?? Like i won''t cause any problems with memory will i? thanks,
Advertisement
not as far as i know.

I moderate at THESE forums.
If I''m not mistaken, that''s the same as using a char* as the argument.

I don''t recommend doing this, as it''s very easy to make mistakes (off-by-1 errors, forgetting a ''\0'', null-pointers, etc.). As long as the string is null-terminated, though, you should be okay.
If you''re programming in C++, you should generally use the standard C++ std::string type. If you''re programming in C, you don''t have much of a choice.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan (C programming language co-inventor)
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement