Thread: change array data type

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    84

    change array data type

    Hello, I was wondering if I had an array of the data type float, is there a way that I could change my entire array to the data type int? It's fine if everything past the decimal point gets chpped off, I'm not trying to round.

    thank you

  2. #2
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    As far as i know....there is no standard way to convert type of arrays....but you can do this
    Code:
    #include<iostream>
    using namespace std;
    int main()
    {
    	float a[]={1.1,2.2};
    	for(int i=0;i<2;i++)
    	{
    		a[i]=int(a[i]);
    		cout<<a[i]<<"  ";
    	}
    	return 0;
    }

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    Code:
    #include<iostream>
    using namespace std;
    int main()
    {
    	float a[]={1.1,2.2};
    	for(int i=0;i<2;i++)
    	{
    		a[i]=int(a[i]);
    		cout<<a[i]<<"  ";
    	}
    	return 0;
    }
    dont forget that this is a C board

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM