help with code..
Posted: Thu Jan 13, 2011 8:19 pm
well i have some questions.. its given to me a routine so as to read large inputs faster than using scanf.. the problem is that i do not quite understand what this rutine does?
the code is:
and my questions are:
why
what's the purpose of it? and why c=buffer[bpos++] and not [bsize++] so as to take the end of the array.. what's the value of bpos in that assignment?
and secondly, i dont get at all the last if, else-if clause...
i would appreciate any help..
the code is:
Code: Select all
#include <stdio.h>
#define BSIZE 1<<16
char buffer[BSIZE];
int bpos = 0, bsize = 0;
int readInt()
{
int d = 0, x = 0;
char c;
while(1)
{
if (bpos >= bsize)
{
bpos = 0;
if (feof(stdin)) return x;
bsize = fread(buffer, 1, BSIZE, stdin);
}
c = buffer[bpos++];
if (c >= '0' && c <= '9') { x = x*10 + (c-'0'); d = 1; }
else if (d == 1) return x;
}
return -1;
}
why
Code: Select all
c = buffer[bpos++];
and secondly, i dont get at all the last if, else-if clause...
i would appreciate any help..