conversion from 'double' to 'unsigned int"

  • Thread starter Thread starter chauhan.alok
  • Start date Start date
C

chauhan.alok

hi
I am a beginner to vc++.

I am opening a file("c:\Mydoc.doc") and reading data from it and afte
that i just want to write data of 1.2 MB part from firs
file("c:\Mydoc.doc") to New file("c:\Newdoc1.doc") and remaining t
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 chauha


-
chauhan.alo
 
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,
 
chauhan.alok said:
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

alok:

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

David Wilkinson
 
Back
Top