fgets 读取中文乱码?
FILE *fp = NULL;
fp = fopen("rr.ini", "r");
char buf[128];
if (fp == NULL)
{
return FALSE;
}
int flag = 0;
while (!feof(fp))
{
flag++;
memset(buf,0,128);
fgets(buf, 128, fp);
CString strPath = Char2WChar(DelEnter(buf));
CString strReg("[reg]");
CString strRun("[run]");
CString strName("[name]");
if (strPath == strReg)
{
memset(buf, 0, 128);
fgets(buf, 128, fp);
strPath = Char2WChar(DelEnter(buf));
if (wcsncmp(strPath.Mid(0,7),_T("regname="),7) == 0)
{
strPath = strPath.Mid(8,strPath.GetLength());
if (strPath.GetLength() > 1)
{
m_ReadIniRegList=strPath;
}
m_ReadIniRegList=(L"null");
}
}
else
{
if (1 == flag)
{
m_ReadIniRegList=L"null";
}
}
if (strPath == strRun)
{
memset(buf, 0, 128);
fgets(buf, 128, fp);
strPath = Char2WChar(DelEnter(buf));
if (wcsncmp(strPath.Mid(0,6),_T("runexe="), 6) == 0)
{
strPath = strPath.Mid(7,strPath.GetLength());
m_ReadIniRunList=strPath;
}
else
{
m_ReadIniRunList = L"----";
}
}
if (strPath == strName)
{
memset(buf, '\0', 128);
fgets(buf, 128, fp); //此处读取的中文就会出现乱码(有的不会出现)
strPath = Char2WChar(DelEnter(buf));
if (wcsncmp(strPath.Mid(0,4),_T("name="), 4) == 0)
{
strPath = strPath.Mid(5,strPath.GetLength());
m_ReadIniNameList = strPath;
break;
}
else
{
m_ReadIniNameList = L"----";
}
}
}
fclose(fp);