Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing data in an int array to a double array

Status
Not open for further replies.

avenhor

Technical User
Joined
Sep 30, 2001
Messages
1
Location
SG
currently I have a two dimensional array that has been defined as int. I would like to redefine or copy these data into another array, but a double array instead. How do I do that?

Currently I've used cast and I've also tried to define the original array as double, but if I do that then the values stored in the original array becomes some very large negative number.
 
Hi,
if you want copy data from int to double you need
only set double value to int value.
i hope i understand you correct. example :

Code:
  int a[3][4];
  double b[3][4];
  for(int i=0; i<3; i++)
    for(int j=0; j<4; j++)
    {
      a[i][j] = i + j;   
      b[i][j] = a[i][j]; //double val = int val
      printf(&quot;\n a[%d][%d] = %d&quot;,i,j,a[i][j]);
      printf(&quot;      b[%d][%d] = %.2e&quot;,i,j,b[i][j]);
    }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top