| ??? 08/21/05 18:14 Read: times |
#99781 - Bad array index Responding to: ???'s previous message |
/*give integer as input get a string as output.
returned strlen is fixed,=5*/
char* tostr(unsigned int num)
{
unsigned int base;
unsigned char rem,x;
char buff[6];
char *ptr=buff;
for(x=4;x>0;--x)
{
base=rpt(10,x);
rem=num/base;
*ptr=(char)rem+0x30;
num-=rem*base;
ptr++;
}
*ptr=(char)num+0x30;
buff[6]=' '; /* OOPS! */
return buff;
}
buff[]'s valid indices are 0 through 5. By using 6, you are likely clobbering some other variable. |
| Topic | Author | Date |
| Keil C51-optimization & Pointers | 01/01/70 00:00 | |
| Bad array index | 01/01/70 00:00 | |
| oops!! | 01/01/70 00:00 | |
| buff[] is auto, not static | 01/01/70 00:00 | |
| Back to basics | 01/01/70 00:00 | |
| Don't shoot the pianist! | 01/01/70 00:00 | |
| Hex file size | 01/01/70 00:00 | |
| Optimization pointers | 01/01/70 00:00 | |
| sprintf() is fairly large | 01/01/70 00:00 | |
| So start a new thread, then! | 01/01/70 00:00 | |
| pls...help | 01/01/70 00:00 | |
I disagree | 01/01/70 00:00 | |
| My dear Watson ! | 01/01/70 00:00 | |
| One size fits all | 01/01/70 00:00 | |
| bin = hex / 2.8 | 01/01/70 00:00 | |
| hexmap | 01/01/70 00:00 | |
| A bit of a sweeping generalisation!! | 01/01/70 00:00 | |
| Keil C51-optimization & Pointers | 01/01/70 00:00 |



