scanf() acting strange
Tim Drury
tim.drury@gtri.gatech.edu
Tue Jul 7 07:59:00 GMT 1998
Thanks Paul.
> int read(int fd ,char * buf,int nbytes)
> {
> int i = 0;
>
> for (i = 0; i < nbytes; i++) {
> *(buf + i) = inbyte();
> if ((*(buf + i) == '\r') || (*(buf + i) == '\n')) {
> *(buf +i)='\n';
I understand this: convert your \r to a \n which, I assume,
is what scanf() is looking for to terminate input?
> outbyte('\r');
> outbyte('\n');
What is this for? I this custom for your system? I don't
want to send stuff back to the host.
> return i+1;
> }
> else
> outbyte(*(buf+i));
ditto here?
> }
> return (i);
> }
> When it reads a \n or \r it breaks out of the loop.
> i never gots incrmented.
> So the number of chars read is reported as one too few.
> The good old off by one bug ;-)
Thanks again,
-tim
More information about the crossgcc
mailing list