Problem on Array Declaration

whats the problem of this declaration

int getLength(char* str)
{
int i;
for(i = 0; str[i] != '\0'; i ++){}
return i;
}

void concatenate(char* s1, char* s2)
{
char temp[getLength(s1) + 1]; /* Error in this line */
}

==================================================================
Errors:
-expected constant expression
-cannot allocate an array of constant size 0
-'temp' : unknown size
Last edited on
Q:
whats the problem of this declaration

A:
Errors:
-expected constant expression
-cannot allocate an array of constant size 0
-'temp' : unknown size

XD

try:
1
2
3
4
void concatenate(char* s1, char* s2)
{
       char* temp = new /* allocate memory here */
}

ref: http://www.cplusplus.com/doc/tutorial/dynamic/ and http://www.cplusplus.com/reference/std/new/
Last edited on
Topic archived. No new replies allowed.