Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good Afternoon,

I'm building an email launcher using Visual C++ forms.
Now i don't know much of c++ so that is why i'm using C standard libraries.

I've a text file with a html coded email inside.

If i create a string with predefinied size say
char mail[150000];

fread works fine

however if i allocate the memory fread only reads a few characters(around 265)

C++
char *mail;
mail=(char*)malloc(sizeof(char)*150000);
fread(mail,1,150000,f);

I've tryed opening the file both normal or binary

Need help,


Content of the file
Addional Details.
fread return value matches the characters on the file.


XML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Mail de Ofertas
</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />


<meta name="ProgId" content="Word.Document" />

<meta name="Generator" content="Microsoft Word 12" />

<meta name="Originator" content="Microsoft Word 12" />

<meta name="Peticion" content="origen=SCQ_SVQ_VGO_XXX&marca=SLP&fdesde=20111202&fhasta=20111203&manual=1&id=PT" />
</head>
<body>

<table width="640" border="0"><tr><td>

<table width="640" border="0">

<tr><td colspan="3"><a target='_blank' href='http://b2b.iberojet.es/entradaMail.aspx?ver=3&marca=SLP&prog=599'><img alt='' src='http://b2b.iberojet.es//contenidos/xml_teletipos/bannermail/slp_0_599.jpg'  width='640' height='175' style='border:none;' /></a></td></tr>

<tr><td height="10"></td></tr>

<tr>

<td align="left"><a target='_blank' href='http://b2b.iberojet.es/entradaMail.aspx?ver=3&marca=SLP&prog=707'><img alt='' src='http://b2b.iberojet.es//contenidos/xml_teletipos/bannermail/slp_1_707.jpg'  width='200' height='175' style='border:none;' /></a></td>

<td align="center"><a target='_blank' href='http://b2b.iberojet.es/entradaMail.aspx?ver=3&marca=SLP&prog=1601'><img alt='' src='http://b2b.iberojet.es//contenidos/xml_teletipos/bannermail/slp_2_1601.jpg'  width='200' height='175' style='border:none;' /></a></td>

<td align="right"><a target='_blank' href='http://www.solplan.es/'><img alt='' src='http://b2b.iberojet.es//contenidos/xml_teletipos/bannermail/slp_3_666.jpg'  width='200' height='175' style='border:none;' /></a></td>

</tr>

</table>


<table width="640" border="0">

<tr>
<td height='30' valign='bottom'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold; color: #003399;'>02 Baleares y Canarias->&nbsp;Lanzarote
</span></td>
</tr>
<tr>
<td style='border:1px solid gray;'>
<TABLE border='0' cellPadding='3' width='635' align='center'>
<tr>
<td width="80" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Destino
</span></td>
<td width="60" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Origen
</span></td>
<td width="68" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Validez
</span></td>
<td width="50" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Desde(&euro;)
</span></td>
<td width="190" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px;    font-weight: bold; color: #003399;'>Descripción
</span></td>
<td width="35" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Etiquetas
</span></td>
<td width="10" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>pdf
</span></td>
<td width="50" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Reservar
</span></td>
</tr>
<tr>
<td width="80" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Lanzarote
</span></td>
<td width="60" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Santiago
</span></td>
<td width="68" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>09/01 - 30/01
</span></td>
<td width="50" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>320,00
</span></td>
<td width="190" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="blank" href='http://b2b.iberojet.es/contenidos/gesofertas/SLP/jpg/SCQACE0100GGFCHSCQ01.jpg' ><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Lanzarote, Súper Ganga Oferta Charter
</span></a></td>
<td width="35" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;'>&nbsp;
</td>
<td width="10" style='background:#F9F9F9; border-bottom: 1px solid #999999; border-bottom-style:dotted ;' align="center" valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="blank" href='http://b2b.iberojet.es/contenidos/gesofertas/SLP/jpg/SCQACE0100GGFCHSCQ01.pdf'><img style="vertical-align:middle;" border="0" title="Imprimir Oferta" src="http://b2b.iberojet.es/teletipos/buscateletipo/img/ico_pdf.gif" /></a></td>
<td width="50" style='background:#F9F9F9; border-bottom: 1px solid #999999; border-bottom-style:dotted ;' align="center" valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="_blank" href='http://b2b.iberojet.es/entradaMail.aspx?ver=0&marca=SLP&mailteletipo=SCQACE0100GGFCHSCQ01&imprimir=si&telorigen=orig' style='font-family: Arial, Helvetica, sans-serif; font-size: 11px;   font-weight: bold; color: #003399;'>Reservar
</a></td>
</tr>
<tr>
<td width="80" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Lanzarote
</span></td>
<td width="60" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Sevilla
</span></td>
<td width="68" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>07/01 - 28/01
</span></td>
<td width="50" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>290,00
</span></td>
<td width="190" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="blank" href='http://b2b.iberojet.es/contenidos/gesofertas/SLP/jpg/SVQACE0100GGFCHSVQ01.jpg' ><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Lanzarote, Súper Ganga Oferta Charter
</span></a></td>
<td width="35" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;'>&nbsp;
</td>
<td width="10" style='background:#F9F9F9; border-bottom: 1px solid #999999; border-bottom-style:dotted ;' align="center" valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="blank" href='http://b2b.iberojet.es/contenidos/gesofertas/SLP/jpg/SVQACE0100GGFCHSVQ01.pdf'><img style="vertical-align:middle;" border="0" title="Imprimir Oferta" src="http://b2b.iberojet.es/teletipos/buscateletipo/img/ico_pdf.gif" /></a></td>
<td width="50" style='background:#F9F9F9; border-bottom: 1px solid #999999; border-bottom-style:dotted ;' align="center" valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="_blank" href='http://b2b.iberojet.es/entradaMail.aspx?ver=0&marca=SLP&mailteletipo=SVQACE0100GGFCHSVQ01&imprimir=si&telorigen=orig' style='font-family: Arial, Helvetica, sans-serif; font-size: 11px;   font-weight: bold; color: #003399;'>Reservar
</a></td>
</tr>
</table></td></tr>
<tr>
<td height='30' valign='bottom'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold; color: #003399;'>02 Baleares y Canarias->&nbsp;Tenerife
</span></td>
</tr>
<tr>
<td style='border:1px solid gray;'>
<TABLE border='0' cellPadding='3' width='635' align='center'>
<tr>
<td width="80" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Destino
</span></td>
<td width="60" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Origen
</span></td>
<td width="68" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Validez
</span></td>
<td width="50" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Desde(&euro;)
</span></td>
<td width="190" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px;    font-weight: bold; color: #003399;'>Descripción
</span></td>
<td width="35" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Etiquetas
</span></td>
<td width="10" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>pdf
</span></td>
<td width="50" align="center" style='border-collapse: collapse; border-bottom: 1px solid #999999;'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: bold; color: #003399;'>Reservar
</span></td>
</tr>
<tr>
<td width="80" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Tenerife
</span></td>
<td width="60" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Vigo
</span></td>
<td width="68" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>09/01 - 30/01
</span></td>
<td width="50" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>300,00
</span></td>
<td width="190" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="blank" href='http://b2b.iberojet.es/contenidos/gesofertas/SLP/jpg/VGOTCI0100GGFCHVGO01.jpg' ><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Tenerife, Súper Ganga Oferta Charter
</span></a></td>
<td width="35" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;'>&nbsp;
</td>
<td width="10" style='background:#F9F9F9; border-bottom: 1px solid #999999; border-bottom-style:dotted ;' align="center" valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="blank" href='http://b2b.iberojet.es/contenidos/gesofertas/SLP/jpg/VGOTCI0100GGFCHVGO01.pdf'><img style="vertical-align:middle;" border="0" title="Imprimir Oferta" src="http://b2b.iberojet.es/teletipos/buscateletipo/img/ico_pdf.gif" /></a></td>
<td width="50" style='background:#F9F9F9; border-bottom: 1px solid #999999; border-bottom-style:dotted ;' align="center" valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="_blank" href='http://b2b.iberojet.es/entradaMail.aspx?ver=0&marca=SLP&mailteletipo=VGOTCI0100GGFCHVGO01&imprimir=si&telorigen=orig' style='font-family: Arial, Helvetica, sans-serif; font-size: 11px;   font-weight: bold; color: #003399;'>Reservar
</a></td>
</tr>
<tr>
<td width="80" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Tenerife
</span></td>
<td width="60" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Santiago
</span></td>
<td width="68" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>03/01 - 31/01
</span></td>
<td width="50" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>300,00
</span></td>
<td width="190" align="left" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;' valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="blank" href='http://b2b.iberojet.es/contenidos/gesofertas/SLP/jpg/SCQTCI0100GGFCHSCQ01.jpg' ><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #666666;'>Tenerife, Súper Ganga Oferta Charter
</span></a></td>
<td width="35" style='background:#EDF1F8; border-bottom: 1px solid #999999; border-bottom-style:dotted;'>&nbsp;
</td>
<td width="10" style='background:#F9F9F9; border-bottom: 1px solid #999999; border-bottom-style:dotted ;' align="center" valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="blank" href='http://b2b.iberojet.es/contenidos/gesofertas/SLP/jpg/SCQTCI0100GGFCHSCQ01.pdf'><img style="vertical-align:middle;" border="0" title="Imprimir Oferta" src="http://b2b.iberojet.es/teletipos/buscateletipo/img/ico_pdf.gif" /></a></td>
<td width="50" style='background:#F9F9F9; border-bottom: 1px solid #999999; border-bottom-style:dotted ;' align="center" valign="top"><a style='color: #003399; font-size: 9px; font-family: Verdana, Arial, Helvetica, sans-serif;text-decoration: none;' target="_blank" href='http://b2b.iberojet.es/entradaMail.aspx?ver=0&marca=SLP&mailteletipo=SCQTCI0100GGFCHSCQ01&imprimir=si&telorigen=orig' style='font-family: Arial, Helvetica, sans-serif; font-size: 11px;   font-weight: bold; color: #003399;'>Reservar
</a></td>
</tr>
</table></td></tr>

</table>


<table width="640" border="0">

<tr><td height="5"></td></tr>

<tr><td colspan="3"><a target='_blank' href='http://b2b.iberojet.es/entradaMail.aspx?ver=3&marca=SLP&prog=691'><img alt='' src='http://b2b.iberojet.es//contenidos/xml_teletipos/bannermail/slp_4_691.jpg'  width='640' height='175' style='border:none;' /></a></td></tr>

</table>

</td></tr></table>

</body>
</html>
Posted
Updated 3-Dec-11 6:26am
v4
Comments
Richard MacCutchan 3-Dec-11 12:35pm    
Just tried this with the data you posted as file content and read the entire file without problems. Step through your code with the debugger to see what's going on.
Richard MacCutchan 3-Dec-11 12:47pm    
If the return value from fread() matches the file size, then how have you determined that it only reads 265 characters?
Sergey Alexandrovich Kryukov 15-Mar-13 14:13pm    
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

There is no reason why this should be so from the code you have shown, but without knowing the content of the file it's difficult to guess what may be happening. You should check carefully the size and content of your input file. I would also suggest capturing the return value from your fread() call to see how many characters are returned.
 
Share this answer
 
Try again by getting the file size & passing it to fread.

C++
long fSize;
// after opening the file
fseek (f , 0 , SEEK_END);
fSize = ftell (f);
rewind (f);
// now pass the size to fread
// (also a good idea to allocate
//  just that much of memory)
fread(mail,1,fSize,f);


Interesting problem. Let me know if it's solved.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900