从某一特定位置读取文件内容

2020-11-13  本文已影响0人  ChennelCiel
FILE *file;
const char *fileName;
fileName= "xxx.txt";
int error = fopen_s(&file, fileName, "r");
if (error != 0)
    puts("Fail!打开文件失败!");

// point to end, get file size(char)
fseek(file, 0L, SEEK_END);
int size = ftell(file);

//  specified location    
unsigned int position = xxx;
unsigned int readSize = xxx;
for (int i = position; i < position+readSize ; i++) {
    if (k < size) {
        fseek(file, i, SEEK_SET);
        char ch = getc(file);
        cout << ch;
    }   
}
上一篇下一篇

猜你喜欢

热点阅读