G
gamehack
Hi all,
I've been designing a program which would need to have a function to
replace values in a string.
For example I could have a string:
"<circle x="%" y="%">" and then I would replace the % with actual
values. But I cannot think of a way to convert an integer(say 5643) to
a NULL terminated string. I'm thinking of writing a function like:
char* get_circle(int x, int y)
{
}
But that would return a char* and not the actual string. So I would
need to dynamically allocate the string(not on the stack) so it is not
deleted automatically after the function ends. Then the code which is
using the result is responsible to free it, isn't it? Any ideas how to
go about implementing this function? I'm not asking for code, just for
directions. Thanks.
PS.
Say you use some function which returns a char* and you have some code
like:
char* c;
c = somefun();
Then surely somefun(); returns a char* which is saved in memory
temporarily and then this is assigned to c. But where does the
temporary value go? Who's responsible for freeing it?
I've been designing a program which would need to have a function to
replace values in a string.
For example I could have a string:
"<circle x="%" y="%">" and then I would replace the % with actual
values. But I cannot think of a way to convert an integer(say 5643) to
a NULL terminated string. I'm thinking of writing a function like:
char* get_circle(int x, int y)
{
}
But that would return a char* and not the actual string. So I would
need to dynamically allocate the string(not on the stack) so it is not
deleted automatically after the function ends. Then the code which is
using the result is responsible to free it, isn't it? Any ideas how to
go about implementing this function? I'm not asking for code, just for
directions. Thanks.
PS.
Say you use some function which returns a char* and you have some code
like:
char* c;
c = somefun();
Then surely somefun(); returns a char* which is saved in memory
temporarily and then this is assigned to c. But where does the
temporary value go? Who's responsible for freeing it?