
AN155
Rev. 1.1 31
putc(*string); // put character at pointer in buffer
string++; // increment pointer
}
}
//-----------------------------------------------------------------------------
unsigned int getuint(void) // get string and convert to int
{
char theChar;
unsigned int i;
i=0; // build value in i
theChar=getc(); // get next character
while( theChar<'0' || theChar>'9') // while not 0-9
theChar=getc();
while(theChar>='0' && theChar<='9') // while 0-9
{
theChar -= '0'; // convert from ASCII
i *= 10; // shift decimal point
i += theChar; // add next digit
theChar=getc();
}
return i; // return int value
}
//-----------------------------------------------------------------------------
void putuint(unsigned int i)
{
char string[7]; // string used to build output
char *sp; // string pointer
sp=string + 6; // build back to front
*sp=0; // insert null character
do
{
sp--; // predecrement pointer
*sp=i%10 + 0x30; // take modulus add 30
i/=10; // divide i by 10
} while (i); // while i not zero
// now output front to back
while (*sp) // while not null character
{
putc(*sp); // put character in buffer
sp++; // increment pointer
}
}
//-----------------------------------------------------------------------------
unsigned char getuchar () // same as getuint but returns uchar
{
char theChar;
unsigned char i;
i=0; // build value in i
theChar=getc(); // get next character
while( theChar<'0' || theChar>'9') // while not 0-9
theChar=getc();
while(theChar>='0' && theChar<='9') // while 0-9
{
theChar -= '0'; // convert from ASCII
i *= 10; // shift decimal point
i += theChar; // add next digit
theChar=getc();
Comentários a estes Manuais