Using some text editors to edit text file, you will see Add Unicode Signature (BOM) checkbox when open Save (As) File Dialogue with encoding UTF-8. So, what happend if you check (uncheck) this box?
The difference between 2 types!
I am using XVI32 to open 2 files, one is saved with Encoding UTF-8 and add BOM, other is saved without BOM.
The differences are 3 first bytes! UTF-8 BOM has EF BB BF chr(237) chr(187) chr(191)
Following is delBOM.c. (Dev-cpp)
#include <windows.h>
#include <stdio.h>
int main(int argn, char * argv[]) {
FILE *fp;
if (argn < 2) {
MessageBox(0, “Where is second argument?”, “PVH”, 0);
return 0;
}
int iFile;
for (iFile = 1; iFile < argn; iFile++) {
fp = fopen(argv[iFile], “r”);
if (!fp) {
MessageBox(0, “Read file failed”, “PVH”, 0);
continue;
}
char szString[65535];
int nRead = fread(szString, sizeof(char), 65535, fp);
//printf(“%d “, nRead);
int iStart = 0;
int iFinish = nRead;
if(szString[0] == -17 && szString[1]==-69 && szString[2]==-65) {
printf(“BOM will be removed”);
iStart = 3;
}
rewind(fp);
fclose(fp);
if (iStart == 0) continue;
fp = fopen(argv[iFile], “w+”); int i;
for (i = iStart; i < iFinish; i++) {
fputc(szString[i], fp);
}
fclose(fp);
}
return 1;
}