Read TXT with Extended Ascii

Asked

Viewed 114 times

0

I made the code below to read a TXT file that contains extended char from ascii table.

int main(void){
printf("%c %c %c %c %c %c %c %c %c \n",205,187,186,187,200,201,205,188);
FILE *ffpOrig=fopen("a.txt", "r");
for(;!feof(ffpOrig);){
  unsigned char ch;
  fread(&ch, sizeof(unsigned char),1, ffpOrig);
  printf("%c",ch);
}
return 0;
}

File a.txt:

However, for the following printf, it does not display/read the characters correctly. It shows: Ôòöòôòéôòòòé.......

PS.: The first printf correctly displays the chars:.

Can someone help me?

Thank you.

  • You can try reading the file as binary (ffpOrig=fopen("a.txt", "rb")) to ensure that bytes will be read as such (rather than interpreted as text).

  • I’ve tried, and the problem continues.

  • 2

    The contents of the file do not have the characters you want...open the file in an editor that shows the contents in hexadecimal, to confirm. (I think the Notepad++ editor does this).

  • 1

    Exchange for printf("%i",ch); and see if the numbering matches. It’s probably what Joseph X said, the characters are not the same. What you call "extended characters" can actually be a completely different set of encodings (there is no "Extended ASCII" table, this is just a concept). Each codepage binds the numbers above 127 to completely different characters. Even what you have shown to be "correct" is not absolutely correct. It is only correct in relation to the codepage you used as reference.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.