linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Division in loop
@ 2009-09-08 14:40 Randi Botse
  2009-09-08 14:47 ` Saurabh Sehgal
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Randi Botse @ 2009-09-08 14:40 UTC (permalink / raw)
  To: linux-c-programming

hi all,

....
int fd, fdp;
unsigned int size;
int progress = 0;
size_t bytes = 0;
void *buffer;
....

/* open fd from a device then create fdp, allocate buffer,, etc. */

while (bytes < size) {
        ret = read(fd, buffer + bytes, size - bytes);
        if (ret == -1) {
            perror("read");
            return -1;
        }
        ret = write(fdp, buffer + bytes, ret);
        if (ret == -1) {
            perror("write");
            return -1;
        }
        bytes += ret;

        progress = (int) ((bytes / size) * 100);
        printf("\rcompleted: %i%%", progress);
        fflush(stdout);
    }

....

I run this loop to receive some data, the printf() seem not updated,
the progress output is
always in it's initial value until the loop was finished. but when i do...

progress = (int) ((bytes / 2) * 100); /* change size to 2 (or random number) */

then it's works... what's wrong here???

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2009-09-11  7:26 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-08 14:40 Division in loop Randi Botse
2009-09-08 14:47 ` Saurabh Sehgal
2009-09-08 14:57 ` Bert Wesarg
2009-09-08 14:58 ` Tim Walberg
2009-09-08 15:09   ` Randi Botse
2009-09-09  0:49   ` Glynn Clements
2009-09-09  2:37     ` Randi Botse
2009-09-09  2:39       ` Randi Botse
2009-09-09  2:52         ` Eric Bambach
2009-09-09  2:57         ` Eric Bambach
2009-09-09 10:12           ` Randi Botse
2009-09-10  0:46         ` Glynn Clements
2009-09-10  7:01           ` Randi Botse
2009-09-10  7:03             ` Manish Katiyar
2009-09-11  7:26             ` Glynn Clements
2009-09-09  0:45 ` Zhenwen Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).