#include <stdio.h>
#include <iostream>
int main()
{
FILE* oFile=fopen("file","wb");
for(int i = 255; i>=0; i--)
fprintf(oFile,"%c",i);
system("pause");
return 0;
}
Now, “file” contains ONLY “weird” characters:
����훗퓕틓탑컏쳍쫋죉웇쓅싃상뺿벽못뢹뚷뒵늳낱꺯겭ꪫꢩꚧ꒥ꊣꂡ麟鲝骛颙隗钕銓邑躏貍誋袉蚇蒅芃肁繿籽穻硹癷瑵牳灱湯汭橫桩晧摥扣恡幟屝婛塙噗呕剓偑乏䱍䩋䡉䙇䑅䉃䁁㸿㰽㨻㠹㘷㐵㈳〱ⸯⰭ⨫⠩☧␥∣‡ḟᰝᨛ᠙ᘗᐕሓထฏࠉ؇Ѕȃ
What’s intriguing for me, using a console stream, everything is OK.
#include <stdio.h>
#include <iostream>
int main()
{
for(int i = 255; i>=0; i--)
printf("%c",i);
system("pause");
return 0;
}
The question is: why there are no “latin” characters in the output file? Even after converting from UCS-2 little endian(why it was automagically selected?) to ascii in the notepad++:
ﳽ﫻ď±î»Żîłî««îŁ©î›§î“Ąî‹Łîˇí»źíłťí«›íŁ™í›—í“•í‹“í‘컏쳍쫋죉웇쓅ě‹ě뺿벽못뢹뚷뒵늳낱꺯ę˛ęŞ«ę˘©ęš§ę’ĄęŠŁę‚ˇéşźé˛ťéŞ›é˘™éš—é’•éŠ“é‚‘čşŹč˛ŤčŞ‹č˘‰čš‡č’…čŠč‚繿籽穻硹癷瑵牳ç±ćąŻć±ć©«ćˇ©ć™§ć‘Ąć‰Łćˇĺąźĺ±ťĺ©›ĺˇ™ĺ™—呕剓ĺ‘乏䱍䩋䡉䙇䑅ä‰ä㸿㰽㨻㠹ă·ăµăłă€±â¸Żâ°â¨«â ©â§âĄâŁâ€ˇá¸źá°ťá¨›á ™á—á•á“á€‘ŕ¸Źŕ°Ťŕ¨‹ŕ ‰Ř‡Đ…Č
I think that one problem you have is that you happen to have started your file with a well known byte order mark, “feff” which is the BOM for UTF-16. This means that many editors will think this is UTF16 where they’d normally default to ASCII/UTF8.
Take a look at your file in hex: