wchar_t reading [closed]
Asked Answered
R

1

0

I have a mistake in the function for reading the file but I don't know what is wrong. all the symbols are read correctly when the symbol is beyond the ASCII table.

while ((c = fgetwc(file)) != WEOF) {
        if (c != L'\n') {
            if (i == buf_length) {
                buf_length += BUF;
                wchar_t *rebuf = realloc(tmp, buf_length * sizeof(wchar_t));
                if (rebuf == NULL) {
                    free(tmp);
                    tmp = NULL;
                    buf_length = 0;
                    return EALLOC;
                } else {
                    tmp = rebuf;
                }
            }
            tmp[i] = (wchar_t)c;
            i++;
        } else {
            list->size++;
            tmp[i] = L'\0';
            insertLast(list, tmp);
            i = 0;
        }
Roux answered 18/12, 2011 at 14:14 Comment(5)
I think your file might not be saved in unicode encodingLenard
The problem is that when it reads some sybmols such like this ďšě that's not saving in linked list :(Roux
When it read the symbol "ď" by this function it has code 196, but it isn't true it have to be u010FRoux
fgetwc() doesn't do what you think it does. It only reads wide characters when the file was opened in binary mode. In text mode it still falls back to 8-bit encoding. You need to document the compiler you use. There are non-standard extensions to deal with Unicode encoded text files.Ezekielezell
You have an off-by-one error by not considering space for the wide null string terminator.Palp
E
0

Is _UNICODE defined? Also, check that you do not get an error (use ferror and feof) when you encounter WEOF as it could mean either.

http://msdn.microsoft.com/en-us/library/c7sskzc1%28v=vs.71%29.aspx

Etiology answered 18/12, 2011 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.