01-18-2013 09:43 AM
I am trying to work out the percentage of file loaded and instead of getting a value between 0 and 100 im getting values like -33000 - can somebody help to find the reason why please?
bytesRead = (int)infile.gcount();
if(bytesRead > 0){
completeBytesRead += bytesRead;
per = (((double)completeBytesRead)/((double)fileSize))*1 00;
percent = per;
printf("file percent %d \n", percent);
fflush( stdout );
dialog_set_progress_toast_level(dialog, percent);thank you for any help you can provide.
Solved! Go to Solution.
01-18-2013 09:54 AM - edited 01-18-2013 10:02 AM
Just a guess - is completeBytesRead initially initialized to zero?
How do you initialize fileSize?
Btw, for better readability this line
per = (((double)completeBytesRead)/((double)fileSize))*100;
can be rewritten as:
per = (double)completeBytesRead / fileSize * 100;
'/' and '*' have the same priority, so this line will be processed left to right.
fileSize will be promoted to double automatically.
01-18-2013 10:14 AM
I init completeBytesRead like...
int completeBytesRead, bytesRead, percent = 0;
and I init fileSize like..
fileSize = filestatus.st_size;
is this wrong? cant load to a device for an hour or so to try any different.
Thanks for the tips on brackets.
01-18-2013 10:17 AM
01-18-2013 12:23 PM
it certainly did fix it - thank you.
regards.