i m confused about sprint syntax- i need to create dynamic mysql query so i have to use it, when i take char * it shows a error while when i take char arr[100] (like this )it work fine..
i read syntax from sprint from multiple sites, and it make myself confuse, i think char pointer is best option because here we odnt need to give the size, but it does not work in my case, can we not use char pointer as first argument of sprint function......
my main problem is , i made a function-
char * d_generate_usr_key_generate_usrkey();
and it's defination like this:-
char * d_generate_usr_key_generate_usrkey()
{
char new_key[8];
sprintf(new_key,"%s0001",fixed_char);// char * fixed_char="amit"
1-printf("%s",new_key);
return new_key;
}
and i m calling it as
char *new_predefined_usr_key;
new_predefined_usr_key=table_object->d_generate_usr_key_generate_usrkey();
2-printf("\n%s",new_predefined_usr_key);
here in this condition it is printing amit0001 two times, no problem with this, but when i m removing 1 printf from inside the function this 2 printf give garbage value, How this is happening.. Pls let me know where i m wrong!!!!