PDA

View Full Version : why does the following code crashes



psychedelic_fur
10-09-2001, 05:30 AM
Hi Friends,
can anyone tell me why does the following code crashes

void init (char** ptr, char initchar, int len )
{
memset ( *ptr, initchar, len );
}


void main()
{
char ary[10];
init( (char**)&ary, 'b', 10 );
}

no-one
10-09-2001, 11:26 AM
because you sending a single dimensional array to a multi-dimensional pointer,

do it as follows,




void init (char* ptr, char initchar, int len )
{
memset (ptr, initchar, len );
}


int main()
{
char ary[10];
init(ary, 'b', 10 );
return 0;
}