PDA

Click to See Complete Forum and Search --> : Arrays


prog_tom
Aug 6th, 2002, 09:57 PM
Is it possible to convert Arrays into Chars?

I want to use Arrays in strcat.

abdul
Aug 6th, 2002, 10:26 PM
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()?

prog_tom
Aug 7th, 2002, 10:25 AM
Just an item in the array, a[1];

abdul
Aug 7th, 2002, 12:26 PM
Try this:

char mychar[10];
itoa(a[1], mychar,10);
//Now you can use "mychar" as your string
strcat(mychar......

prog_tom
Aug 7th, 2002, 08:26 PM
how about a whole array?, say a[0],a[1],a[2]

prog_tom
Aug 7th, 2002, 08:43 PM
and isn't itoa used only for integers to strings? a[] are also chars in this case, would it report error?

abdul
Aug 7th, 2002, 10:56 PM
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.

for(int i=0;i<=sizeof(a);i++)
{
strcat(mainstring, a[i]);
}

CornedBee
Aug 13th, 2002, 06:01 AM
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.