最后一条数据读了两次???怎么改哇
m_downFile = fopen("DownloadData.dat","r");//打开文件下载列表的记录文件
if (m_downFile==NULL)
{
//fclose(m_downFile);
return 0;
}
else
{
while(!feof(m_downFile))
{
//if (!feof(m_downFile))
//{
DOWNLOAD_FILE_LIST downlist;
CString str;
fread(&downlist, 1, sizeof(DOWNLOAD_FILE_LIST), m_downFile);
int count = m_downloadlist.GetItemCount();
//count++;
m_downloadlist.InsertItem(count, str,20);
m_downloadlist.SetItemText(count,0, downlist.FileName);
str.Format("%lld",downlist.size);
m_downloadlist.SetItemText(count, 1, str);
str.Format("%lld",downlist.downsize);
m_downloadlist.SetItemText(count, 2, str);
m_downloadlist.SetItemText(count, 5, downlist.Uuid);
//}
//else
//{
}
fclose(m_downFile);
//break;
}
}
不要使用
while (条件)
更不要使用
while (组合条件)
要使用
while (1) {
if (条件1) break;
//...
if (条件2) continue;
//...
if (条件3) return;
//...
}
因为前两种写法在语言表达意思的层面上有二义性,只有第三种才忠实反映了程序流的实际情况。
典型如:
下面两段的语义都是当文件未结束时读字符
whlie (!feof(f)) {
a=fgetc(f);
//...
b=fgetc(f);//可能此时已经feof了!
//...
}
而这样写就没有问题:
whlie (1) {
a=fgetc(f);
if (feof(f)) break;
//...
b=fgetc(f);
if (feof(f)) break;
//...
}
类似的例子还可以举很多。