简体   繁体   中英

Can ftell use for non-ASCII characters?

This line

Assert(pos == ftell(file)); 

is used in my code, when file contains non-ASCII characters, this line failed.

What should I do?

To make it clear, here is the whole function updated:

int getTerminatedString(char * dest, int length) 
{
    char * rv  = fgets(dest,length,file);
    int len = -1;
    if(rv)
    {
        len = strlen(rv);
        pos += len;
        assert(pos == ftell(file));

    }
    return len;
}

Thanks!

如果您以二进制模式打开文件,例如fopen("yourfile","rb") ,则ftell将给出文件中的偏移量,而与内容无关。

Is the dest buffer large enough to contain all the characters AND a final terminating zero byte as well?

If the buffer pointer by the dest pointer is too small the program may overwrite in the memory something it should not - that is one possible way to get the SIGABRT.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM