Mix of types into a char pointer

Hello Everybody,

This is my first post and I would like to ask you a question about a mix of types into a char pointer.

I have defined a char pointer that will be filled with information from different types (int, float and char mainly) through sprintf. When I compile i get this message "warning: deprecated conversion from string constant to ‘char*’" and when I run I get segmentation fault.

I could use string types but the problem is that I have to convert one to type to an specific type and finally I have to convert this string into a char because mysql function don't accept string.

I have been seeking information but I didn't find a similar case.

Any hints??...thank you

Billy
Last edited on
What code is causing this? I assume you have something like:
1
2
3
char *a;
a = "hello";
sprintf(a, "%d", 5);


? That would explain the error, and indicate you should just stay away from char* and use strings until you actually understand how pointers and string constants etc work.
I have something like this:

1
2
3
4
5
char *str;
int str2=23;
float s=12.5;
char *f="hello";
sprintf(str,"%d %f %s ",str2,s,f);

 
const char *f="hello"; //string literals are constant 


 
char *str; //str is uninitialized 


Discard this C stuff and do it the C++ way. You won't screw up that badly with that.
OK....I have many parts in my program that is concatenating information in this way and the solution (not god solution of course) that I have decided to use is to give a dimension to str and works good and there is no warning messages.

Thank you hanst99
Topic archived. No new replies allowed.