Hi, does anyone know why I can use 'sizeof()' but not 'strlen()' for defining the size of an array. I get the following error message in the picture I've attached:
Attachment 15077
Thanks in advance.
Printable View
Hi, does anyone know why I can use 'sizeof()' but not 'strlen()' for defining the size of an array. I get the following error message in the picture I've attached:
Attachment 15077
Thanks in advance.
Because sizeof() is evaluated at compile time, whereas strlen() is evaluated at run-time.
Also, only C99 supports variable length arrays of the form you're using.
What you need to write in C++ is
char *asterisk = new char[ strlen(s) + 1 ];
What you need to write in C++ is:
std::string asterisk;