环境:VC2008 SP1
?
?
?
ReadMe.txt内容:
1111;
2222;
3333;
?
?
const int BUFFER = 1024*20; int _tmain(int argc, _TCHAR* argv[]) { char buffer[BUFFER]; memset(buffer, 0, BUFFER); FILE *pFile; pFile = fopen("ReadMe.txt", "r"); if(NULL==pFile) { printf("err, %d\n", GetLastError()); return 0; } int nHasRead; nHasRead = fread(buffer, 1, BUFFER, pFile); //buffer[nHasRead]='\0'; printf("fread size:%d, \n%s\n", nHasRead, buffer); fclose(pFile); return 0; }
?
输出
fread size:17,
1111;
2222;
3333;3;
请按任意键继续. . .
const int BUFFER = 1024*20;改为 1024*4-1;
输出
fread size:17,
1111;
2222;
3333;
请按任意键继续. . .