L
lasek
Hi all,
i have a trouble understanding this:
example:
#include....
char * testA(void);
char * testB(void);
char * testC(void);
int main(void)
{
char * acMsg=NULL;
....
strcpy(acMsg,testA());
strcpy(acMsg,testB());
strcpy(acMsg,testC());
return 0;
}
char * testA(void)
{
char * acMsg=NULL;
acMsg=malloc((14+1)*sizeof(char));
strncpy(acMsg,"THIS IS A TEST,14);
return acMsg;
// free???
}
char * testB(void)
{
char acMsg[]="THIS IS A TEST";
// this isn't correct (i hope)becaust i try to
return a local address(after this call i
lost the address of 'acMsg')
return &acMsg[0];
}
char * testC(void)
{
char acMsg[]="THIS IS A TEST";
char *acMsg_B=NULL;
// this isn't correct becaust i try to
return a local address(after this call i
lose thi variable address)(??)
acMsg_B=acMsg;
return acMsg_B;
// free??
}
Now...one of these examples are correct...because i feel confuse..
Thanks all and have i nice day.
i have a trouble understanding this:
example:
#include....
char * testA(void);
char * testB(void);
char * testC(void);
int main(void)
{
char * acMsg=NULL;
....
strcpy(acMsg,testA());
strcpy(acMsg,testB());
strcpy(acMsg,testC());
return 0;
}
char * testA(void)
{
char * acMsg=NULL;
acMsg=malloc((14+1)*sizeof(char));
strncpy(acMsg,"THIS IS A TEST,14);
return acMsg;
// free???
}
char * testB(void)
{
char acMsg[]="THIS IS A TEST";
// this isn't correct (i hope)becaust i try to
return a local address(after this call i
lost the address of 'acMsg')
return &acMsg[0];
}
char * testC(void)
{
char acMsg[]="THIS IS A TEST";
char *acMsg_B=NULL;
// this isn't correct becaust i try to
return a local address(after this call i
lose thi variable address)(??)
acMsg_B=acMsg;
return acMsg_B;
// free??
}
Now...one of these examples are correct...because i feel confuse..
Thanks all and have i nice day.