int main()
{
FILE *pfile;
int inum1,inum2;
char clocation[40] = "/home/nelsonchung/Code/config.txt";
//if (( pfile = fopen(clocation,"r")== NULL))
if (( pfile = fopen(clocation,"r")) == NULL)
{
printf("File could not be opened\n");
}
else
{
fscanf(pfile,"%d %d",&inum1,&inum2);
while(!feof(pfile)){
printf("\n%d %d",inum1,inum2);
fscanf(pfile,"%d %d",&inum1,&inum2);
}
}
fclose(pfile);
return 0;
}
MFC
CString strconfigfilepath = "\\SDMMC\\FMTOOLconfig.txt";
CString strFMFreq1(_T(""));
CString errormessage = "Can't found config";
//CStdioFile f;
CFile f;
if( ! f.Open( strconfigfilepath, CFile::modeRead ) ) //沒有讀到設定檔 就關閉程式
{
AfxMessageBox(strconfigfilepath);
exit(0);
}
//char pbuf[100];
BYTE pbuf1[5];
BYTE pbuf2[5];
BYTE pbuf3[5];
BYTE pbuf4[5];
UINT nBytesRead1 = f.Read( pbuf1, 2 ); //抓取頭兩個 87
strFMFreq1 = pbuf1;
iFMFreqfirstfront = _ttoi(strFMFreq1);
// strFMFreq1.Format(_T("%d"),a1);
// AfxMessageBox(strFMFreq1);
UINT nBytesRead2 = f.Read( pbuf2, 1 ); //濾過.
nBytesRead2 = f.Read( pbuf2, 1 ); //抓取接下來的小數 5
strFMFreq1 = pbuf2;
iFMFreqfirstlast = _ttoi(strFMFreq1);
// strFMFreq1.Format(_T("%d"),a2);
// AfxMessageBox(strFMFreq1);
UINT nBytesRead3 = f.Read( pbuf3, 1 ); //濾過空格
nBytesRead3 = f.Read( pbuf3, 3 ); //抓取接下來的數字 108
strFMFreq1 = pbuf3;
iFMFreqsecondfront = _ttoi(strFMFreq1);
// strFMFreq1.Format(_T("%d"),a3);
// AfxMessageBox(strFMFreq1);
UINT nBytesRead4 = f.Read( pbuf4, 1 ); //濾過.
nBytesRead4 = f.Read( pbuf4, 1 ); //抓取接下來的小數 0
strFMFreq1 = pbuf4;
iFMFreqsecondlast = _ttoi(strFMFreq1);