From: Zhenwen Xu <helight.xu@gmail.com>
To: Randi Botse <nightdecoder@gmail.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: Division in loop
Date: Wed, 9 Sep 2009 08:45:31 +0800 [thread overview]
Message-ID: <20090909004531.GA3264@helight> (raw)
In-Reply-To: <34e1241d0909080740m5a3c3098xa48f275f2cf2fd3b@mail.gmail.com>
On Tue, Sep 08, 2009 at 09:40:30PM +0700, Randi Botse wrote:
> 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);
printf them all and check them:
printf("\rcompleted: %i%% bytes: %d size: %d \n", progress, bytes, size);
> 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???
> --
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
--
--------------------------------
http://zhwen.org - Open and Free
prev parent reply other threads:[~2009-09-09 0:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090909004531.GA3264@helight \
--to=helight.xu@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
--cc=nightdecoder@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.