79288667

Date: 2024-12-17 16:36:18
Score: 1
Natty:
Report link

You're returning a single char. Also, what happens if thine input c-string is longer than 20 chars? Either first scan for the length and then malloc, or malloc fixed lenght, set to zero (depending on OS) and break the loop before reaching that lenght.

char * copyStr(const char * str) { int max_length = 20; char * newStr = new char(max_length); for (p=0; *str != '\0' && p < max_length; ++p) { *newStr = *str[p]; }

return newStr; }

Reasons:
  • No code block (0.5):
  • Contains question mark (0.5):
Posted by: rhavin