Re: Division in loop

Saurabh Sehgal <[email protected]>
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
Where do you initialize the variable size and to what value ?

On Tue, Sep 8, 2009 at 10:40 AM, Randi Botse <[email protected]> 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);
>        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 [email protected]
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



--
Saurabh Sehgal
E-mail:     [email protected]
Phone:     647-831-5621
LinkedIn: http://www.linkedin.com/pub/1/7a3/436
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.