Mail Archives: djgpp/1998/04/17/17:01:36
Gerhard W. Gruber schrieb in Nachricht <35360BD4 DOT 5DB6C8C5 AT sis DOT co DOT at>...
>I just encountered a strange thing. I was using a loop that process a
buffer.
>When the index is outside the buffersize the code should read the next
block
>from the file and continue. To do this I'm using the modulo operator but
there
>seems a bug with this.
>
>bl = BufLen % i;
>
>gives following results:
>BufLen = 4096
>i = 1
>bl = 0
>
thats correct
>i = 2
>bl = 0
>
>i = 3
>bl = 1 ???????
what did you expect ?
4096 div 3 = 1365 mod 1
(1365*3=4095 +1 =4096)
>
>All variables are unsigned long
>
>I just checked the code and substituted "bl = BufLen % i" with "bl = i /
BufLen"
>and this works fine.
" / " and " % " are different things.
" / " is the division operator
" % " is the modulo operator
In your case, to get the block number, you use " bl = i / Buflen "
and to get the position inside the block, you use " p = i % Buflen "
Elias Pschernig
- Raw text -