S
s88
Hello All:
I'm trying to make a string buffer for my APIs. For example:
void test(char * str){
sprintf(str,"inner test\n");
}
int main(void){
int i = -5;
char *str=(char*)malloc(sizeof(char)*100);
sprintf(str,"\number is %d\n",i);
test(str);
printf("STR IS %s\n",str);
return 0;
I want the char array str contains "\nnumber is -5\ninner test\n", but
the result is "\ninner test\n". I know the str means that the beginning
pointer of the cahr array. So, as I invoke the test function, the
sprintf of teh test function write down the characters from the
beginning of the str.
How to slove this problem?
Thank you!
Dave.
I'm trying to make a string buffer for my APIs. For example:
void test(char * str){
sprintf(str,"inner test\n");
}
int main(void){
int i = -5;
char *str=(char*)malloc(sizeof(char)*100);
sprintf(str,"\number is %d\n",i);
test(str);
printf("STR IS %s\n",str);
return 0;
I want the char array str contains "\nnumber is -5\ninner test\n", but
the result is "\ninner test\n". I know the str means that the beginning
pointer of the cahr array. So, as I invoke the test function, the
sprintf of teh test function write down the characters from the
beginning of the str.
How to slove this problem?
Thank you!
Dave.