Is it possible to convert Arrays into Chars?
I want to use Arrays in strcat.
Printable View
Is it possible to convert Arrays into Chars?
I want to use Arrays in strcat.
What type of array is it and are you trying to convert an item of the array or the whole array? If the whole array then how should it be appended to your string using strcat()?
Just an item in the array, a[1];
Try this:
PHP Code:char mychar[10];
itoa(a[1], mychar,10);
//Now you can use "mychar" as your string
strcat(mychar......
how about a whole array?, say a[0],a[1],a[2]
and isn't itoa used only for integers to strings? a[] are also chars in this case, would it report error?
If you have characters in the elements of your array then you can simply loop through each item and append the text from it to your main string. So the code I wrote above won't work if you have anything other than integers in your array.
PHP Code:for(int i=0;i<=sizeof(a);i++)
{
strcat(mainstring, a[i]);
}
Abdul: that code won't work
prog_tom: how about saying exactly what you want to do. What is in the array, what are you trying to do with it, maybe give an example.
Only if it still matters of course.