This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Retrieving data from array.

Hi,
I am trying to retrieve data from an array "Buf" to register but am unable to do so.

Below is my code:

>>>>
long T_msec,Div= 360000;
int T_hours;
char Buf[3];
while(1)
{ check_digit();
T_msec = oncount;
T_hours = (int)(T_msec/Div);
sprintf(Buf,"%ud",(int)(T_msec/Div));
hour0digit = Buf[0];
hour1digit = Buf[1];
hour2digit = Buf[2];


// hour3digit = Buf[3];
p07 = 0;
}
<<<<

Please help me..

Aniket

Parents
  • hi,

    I am trying to retrieve data from an array "Buf" to register but am unable to do so.

    char Buf[3];
    sprintf(Buf,"%ud",(int)(T_msec/Div));
    
    Ex: 252000000ul; //700 hours;

    You are in trouble here -- you should either make array enough long or limit number of printed chars by %.number modifier for sprintf()
    For example, "700" requires 4 bytes (note null-terminator at the end of string).

    Then look at assembler code generated by compiler. It may be that optimizer ejects some lines then read more about nonvolatile keyword.

    Regards,
    Oleg

Reply
  • hi,

    I am trying to retrieve data from an array "Buf" to register but am unable to do so.

    char Buf[3];
    sprintf(Buf,"%ud",(int)(T_msec/Div));
    
    Ex: 252000000ul; //700 hours;

    You are in trouble here -- you should either make array enough long or limit number of printed chars by %.number modifier for sprintf()
    For example, "700" requires 4 bytes (note null-terminator at the end of string).

    Then look at assembler code generated by compiler. It may be that optimizer ejects some lines then read more about nonvolatile keyword.

    Regards,
    Oleg

Children
No data