Jump to content
Sign in to follow this  
hvn0005

Can I Write For Loop Array In Boostc?

Recommended Posts

why wouldn't this work??? can anyone help me??

 

 

int j;

unsigned char x[40];

 

void array(void)

{

for (j=0; j < size; j++)

x[j]=226 + j;

}

 

and

 

void main( void)

{

unsigned char data[40];

unsigned char i = 0;

unsigned int k;

int number = 0;

//int num=0;

 

Setup(); // Setup the Ports etc.

 

while(1) //endless loop

{

array();

set_bit(porta,1);

delay_s(1);

clear_bit(porta,1);

delay_s(1);

 

adc_go =1;

while (adc_go);

////////////////////////////////////////////////

 

for (k=0; k < size; k++);

 

<<<<<<</*just the for loop part here doesn't work*/ >>>>>> {

 

if (x[k] == adresl)

number = k - 29;

break;

}

//////////////////////////////////////////////////

data[i++] = number;

if (i==40)

i=0;

count++;

}

}

Share this post


Link to post
Share on other sites
can someone please tell me why this array doesn't work???

 

int j;

unsigned char x[40];

 

 

void array(void)

{

        for (j=0; j < size; j++)

        x[j]=226 + j;

}

 

please help!!

 

 

Hi hvn0005,

 

I am not much of a C programmer, but I can see some mistakes in your program.

You declared J to be an int by adding something to it does not change the type, it stays an int unless something is higher in rank than int.

You declared X[] to be an array of char to which you want to assign a value of int.

The other one I see is in the for statement, the end condition goes to something which is not declared here but hopefully elsewhere.

Even if J was declared a char, the sum 226+40 would make 266, which is bigger than a char can hold.

 

I hope this helps.

 

Frans.

Share this post


Link to post
Share on other sites

Your code uses identifier 'size' that is not defined anywhere.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

thz guys, I found the problem. I wonder why i can't define a global char in boostC?? Also why does the order of the function in you code matter??

Share this post


Link to post
Share on other sites
...I wonder why i can't define a global char in boostC?? Also why does the order of the function in you code matter??...

 

BoostC doesn't have any problems with globals and doesn't require any order in functions.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...