CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

storing integer in an array

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
chingB



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

storing integer in an array
PostPosted: Mon Jan 12, 2004 4:11 am     Reply with quote

Hi,

I need help on how to store an integer in an array? Say I have the following:
numb1 = 16
numb2 = 25
numb3 = 20
numb4 = 4

Any code snippet to store these numbers to an array? say...
array1[0] = 16
array1[1] = 25
array1[2] = 20
array1[3] = 4

I'll appreciate any help.

Thank u.
Ttelmah
Guest







Re: storing integer in an array
PostPosted: Mon Jan 12, 2004 5:04 am     Reply with quote

chingB wrote:
Hi,

I need help on how to store an integer in an array? Say I have the following:
numb1 = 16
numb2 = 25
numb3 = 20
numb4 = 4

Any code snippet to store these numbers to an array? say...
array1[0] = 16
array1[1] = 25
array1[2] = 20
array1[3] = 4

I'll appreciate any help.

Thank u.


What you post will work.

Obviously, you need 'array1' declared, and large enough to hold the values. So:

int array1[4];

Remember all your lines need the ';' terminator.
You could also declare the array to be 'pre-filled' with the numbers, as:

int array1[] = {16,25,20,4};

The compiler will automatically make the array large enough to hold the number of values declared.
These values will be stored into the array, when the code starts, but the numbers can then be changed as needed.
This differs from a 'constant' array, such as:

const int array1[] = {16,25,20,4};

Which will contain the same numbers, but they then cannot be changed.

Best Wishes
chingB



Joined: 29 Dec 2003
Posts: 81

View user's profile Send private message

Re: storing integer in an array
PostPosted: Mon Jan 12, 2004 7:49 am     Reply with quote

chingB wrote:
Hi,

I need help on how to store an integer in an array? Say I have the following:
numb1 = 16
numb2 = 25
numb3 = 20
numb4 = 4

Any code snippet to store these numbers to an array? say...
array1[0] = 16
array1[1] = 25
array1[2] = 20
array1[3] = 4

I'll appreciate any help.

Thank u.


what if numb1, numb2, numb3, & numb4 are integer values that varies depending on the program... say a counter that changes depending on a condition... wen a condition are met then the current integer value of numb1, numb2, numb3, & numb3 should be stored in an array.

Can u comments on this.

Thnx
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: storing integer in an array
PostPosted: Mon Jan 12, 2004 8:47 am     Reply with quote

chingB wrote:

what if numb1, numb2, numb3, & numb4 are integer values that varies depending on the program... say a counter that changes depending on a condition... wen a condition are met then the current integer value of numb1, numb2, numb3, & numb3 should be stored in an array.

Can u comments on this.

Thnx


You can change the array of interers from 8 bit to 16 bit but only at compile time.

Int8 Buffer[8];
or
Int16 Buffer[8];
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 12, 2004 9:08 am     Reply with quote

Code:

if (condition)
{
  array1[0] = numb1;
  array1[1] = numb2;
  array1[2] = numb3;
  array1[3] = numb4;
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group