I have string,int,float values and trying to assign those values to char* c[] array like this.
char *str = "helloo";
int int = 1000;
short st1[]={32760};
float flt = 2.345;
char* c [] = {(char*)int1,(char*)str,(char*)flt,(char*)st1};
but for float getting illegal explicit conversion from ‘float’ to ‘char * ‘
anybody tel me how to assign?
You can’t just cast those types and expect to get useful results. Casting is a minimal operation which can work to transform data in certain predefined ways, but it won’t (for example) intelligently turn integers into their string representations.
That’s why your compiler is complaining.
If you want the string representation of numeric data, you have to convert them differently, with something like:
If you’re looking to get string representations of them all, you can do something like:
And be aware that, although C and C++ have very similar idioms, and are mostly compatible if you stick to a subset, they are not the same language and the best way to do something changes dramatically depending on the actual language you’re using.
For example, it’s rarely necessary to use C-style strings in C++ since that language provides an impressive real string type. Ditto for
malloc/freeas opposed tonew/deleteand many other aspects.Questions should generally be tagged C or C++, rarely both.