FREAD问题. [英] FREAD problem .

查看:71
本文介绍了FREAD问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好,

我正在使用Visual C ++表单构建电子邮件启动器.
现在我对C ++不太了解,所以这就是为什么我使用C标准库.

我有一个带有html编码电子邮件的文本文件.

如果我创建一个具有预定大小的字符串,请说
char mail[150000];

fread效果很好

但是,如果我分配内存,fread仅读取几个字符(大约265个字符)

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)

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


我尝试打开普通文件或二进制文件

需要帮助,


文件内容
其他详细信息.
fread返回值与文件上的字符匹配.



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.


<!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>

推荐答案

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.
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.


Try again by getting the file size & passing it to fread.

Try again by getting the file size & passing it to fread.

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.



Interesting problem. Let me know if it''s solved.


这篇关于FREAD问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆