Guest_imported
New member
- Jan 1, 1970
- 0
Dear all,
In my program:
int main()
{
....
char *tmp1=new char[10];
strcpy(tmp1,"abcdefgh"
..........
char *tmp2=strdup(Somefunction(tmp1));
....//use tmp2 and tmp1 in the code below
return 0;
}
char* Somefunction(char *instr)
{
outstr=strdup(instr);
.....//do some manipulation on outstr
.....//such that the original string is not distorted
return outstr;
}
question 1:when I use strdup, do I need to check whether the return value is null,
just like malloc?
question 2:how can I free the outstr?
Thank you very much!
In my program:
int main()
{
....
char *tmp1=new char[10];
strcpy(tmp1,"abcdefgh"
..........
char *tmp2=strdup(Somefunction(tmp1));
....//use tmp2 and tmp1 in the code below
return 0;
}
char* Somefunction(char *instr)
{
outstr=strdup(instr);
.....//do some manipulation on outstr
.....//such that the original string is not distorted
return outstr;
}
question 1:when I use strdup, do I need to check whether the return value is null,
just like malloc?
question 2:how can I free the outstr?
Thank you very much!