Horace1
Yes. It was what I did as you said.
Is it OK not to call free() in the fun()?
Charles...
User Profile
Collapse
-
Dear Horace1
Glad to receive your reply again. You example worked well. Thank for your time.
However, I would like to keep return type of fun() be char*, because the function will be called by macro like:
#define MACRO1 fun("aaa")
#define MACRO2 fun("bbb")
....
I though malloc() could help as you advised. The only problem was how to free the memory in the...Leave a comment:
-
Dear Horace1
malloc() did solve the problem. It is what I expected. Thank you.
However, as you reommended, how could I free() the memory if I need to return sTmp in the fun()? Could I free() the memory outside the fun()?
Please help.
Thank you
CharlesLeave a comment:
-
Sorry for my mistake. There shouldn't be static keyword.
If fact, the problem still existed when I removed it.
Please help. Thank you.Leave a comment:
-
Dear horace1
So how could I fix this problem? Please help.
Charles...Leave a comment:
-
sprintf() problem
I encountered the problem as follows:
...Code:#include <stdio.h> char* fun(char* b) { char* sTmp; static char d[BUFSIZ]; bzero(d, BUFSIZ); sprintf(d, "%s:%s", "Test", b); sTmp = d; return sTmp; } main() { char a[100]; char b[100]; char tmp[100]; bzero(tmp, 100); strcpy(a,
No activity results to display
Show More
Leave a comment: