Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C: Casting an int array to a double array?

Options
  • 09-12-2004 10:30pm
    #1
    Registered Users Posts: 3,329 ✭✭✭


    Is it possible to convert an int array to a double array?

    I have written a function which accepts an array of doubles as an argument.

    Most of the time I will be passing an array of doubles to it, but in one location in my program, I need to pass an array of ints to it.

    I've tried casting the array to a double array, but no luck.

    Is there a way of doing this? I might be doing it wrong.

    I suppose I could always use a for loop to cast each individual array element to a double, and then put those doubles into a new array...


Comments

  • Registered Users Posts: 1,865 ✭✭✭Syth


    A for loop does seem like the best way to do it...


  • Registered Users Posts: 3,329 ✭✭✭radiospan


    Yep, that did it, thanks.
    for( i= 0; i<= 7; i++ ) {
    				doublebytes[i] = double(bytes[i]);
    			}
    


  • Registered Users Posts: 7,276 ✭✭✭kenmc


    why would you not handle it as a double always?
    or, at least pass it as an unadulterated array to the function and let the function cast the necessary elements to ints inside it if it still needs to play with ints??
    but yeah, you basically can't cast an array of things at once


Advertisement