Results 1 to 8 of 8

Thread: Arrays

  1. #1

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Arrays

    Is it possible to convert Arrays into Chars?

    I want to use Arrays in strcat.

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    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()?
    Baaaaaaaaah

  3. #3

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    Just an item in the array, a[1];

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  4. #4
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Try this:
    PHP Code:
    char mychar[10];
    itoa(a[1], mychar,10);
    //Now you can use "mychar" as your string
    strcat(mychar...... 
    Baaaaaaaaah

  5. #5

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    how about a whole array?, say a[0],a[1],a[2]

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  6. #6

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810
    and isn't itoa used only for integers to strings? a[] are also chars in this case, would it report error?

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  7. #7
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    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(mainstringa[i]);

    Baaaaaaaaah

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width