By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,441 Members | 998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,441 IT Pros & Developers. It's quick & easy.

conversion from 'double' to 'unsigned int"

P: n/a

hi
I am a beginner to vc++.

I am opening a file("c:\Mydoc.doc") and reading data from it and after
that i just want to write data of 1.2 MB part from first
file("c:\Mydoc.doc") to New file("c:\Newdoc1.doc") and remaining to
other file("c;\Newdoc2.doc"). Code is Giving warning .
Pls Help me How these waring can be removed?

Code is:
double dSplitsize,dNumBytes;
FILE * oFile , * sFile;
int intnumr;

oFile = fopen ("c:\Mydoc.doc", "rb");
sFile = fopen ("c:\Newdoc1.doc" , "wb" );
dSplitsize=1.2f;
dNumBytes= dSplitsize*1024*1024;
intnumr= fread (buff1,sizeof(char),dNumBytes,oFile);//warning c4244:
intnumw= fwrite(buff1,sizeof(char),dNumBytes,sFile);//warning c4244:

warning C4244: 'argument' : conversion from 'double' to 'unsigned int',
possible loss of data.

Thanks in advance

alok singh chauhan

--
chauhan.alok
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Mar 23 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
first, you have to double your \

oFile = fopen ("c:\\Mydoc.doc", "rb");

Then, you have to cast dNumBytes to unsigned int, as you can only use
integer value for number of bytes to read.

This warning tells only you that if in your double there's an non
integer value (i mean for example 1,32), it will only use the int part.
So, cast it explicitly to avoid this warning
Best,

Mar 23 '06 #2

P: n/a
chauhan.alok wrote:
hi
I am a beginner to vc++.

I am opening a file("c:\Mydoc.doc") and reading data from it and after
that i just want to write data of 1.2 MB part from first
file("c:\Mydoc.doc") to New file("c:\Newdoc1.doc") and remaining to
other file("c;\Newdoc2.doc"). Code is Giving warning .
Pls Help me How these waring can be removed?

Code is:
double dSplitsize,dNumBytes;
FILE * oFile , * sFile;
int intnumr;

oFile = fopen ("c:\Mydoc.doc", "rb");
sFile = fopen ("c:\Newdoc1.doc" , "wb" );
dSplitsize=1.2f;
dNumBytes= dSplitsize*1024*1024;
intnumr= fread (buff1,sizeof(char),dNumBytes,oFile);//warning c4244:
intnumw= fwrite(buff1,sizeof(char),dNumBytes,sFile);//warning c4244:

warning C4244: 'argument' : conversion from 'double' to 'unsigned int',
possible loss of data.

Thanks in advance

alok singh chauhan

--
chauhan.alok
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------


alok:

You have to cast dNumBytes to unsigned int to get rid of the warning.

David Wilkinson
Mar 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.