C equivalent to fstream's peek

我的未来我决定 提交于 2019-11-27 04:58:52

fgetc+ungetc. Maybe something like this:

int fpeek(FILE *stream)
{
    int c;

    c = fgetc(stream);
    ungetc(c, stream);

    return c;
}

You could use a getc followed by an ungetc

Charles Ma

you'll need to implement it yourself. use fread to read the next character and fseek to go back to where you were before the read

EDIT:

 int fsneaky(FILE *stream, int8_t *pBuff, int sz) {
    sz = fread(pBuff, 1, sz, stream)
    fseek(pFile, -sz, SEEK_CUR);
    return(sz);
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!