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,te stA());
strcpy(acMsg,te stB());
strcpy(acMsg,te stC());
return 0;
}
char * testA(void)
{
char * acMsg=NULL;
acMsg=malloc((1 4+1)*sizeof(cha r));
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...becau se 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,te stA());
strcpy(acMsg,te stB());
strcpy(acMsg,te stC());
return 0;
}
char * testA(void)
{
char * acMsg=NULL;
acMsg=malloc((1 4+1)*sizeof(cha r));
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...becau se i feel confuse..
Thanks all and have i nice day.
Comment