c - reading first line in a file gives me a "\357\273\277" prefix in the first row -


this question has answer here:

when use function readthenrow row=0 (i read first row) find 3 first chars \357 ,\273 , \277. found prefix how related utf-8 files, files have prefix , don't :( . how ignore type of such prefixes in files want read them?

int readthenrow(char buff[], int row) {  int file = open("my_file.txt", o_rdonly); if (file < 0) {     write(2, "closing fifo unsuccessful\n", 31);     exit(-1); }  // function's variables int = 0; char ch; // temp variable read int check; // helping variable checking read function  // read till reach needed row while (i != row) {      // read 1 char     check = read(file, &ch, 1);     if (check < 0) {         // write error message user         write(2, "error occurred in reading\n", 27);         exit(-1);     }      if (check < 0) {         // if means reached end of file         return -1; // couldn't read n row (n bigger x)     }     printf("%c",ch);     // check char \n     if (ch == '\n') {         i++;     } }  // read number received buffer = 0;  {     // read 1 char     check = read(file, buff + i, 1);     if (check < 0) {         // write error message user         write(2, "error occurred in reading\n", 27);         exit(-1);     }      // if reached end of file     if (check == 0) {         break;     }     i++;  } while (buff[i - 1] != '\n');  // put \0 in end of string  buff[i - 1] = '\0'; return 1; // return reading successful      // try close file if (close(file) < 0) {     write(2, "closing fifo unsuccessful\n", 31);     exit(-1); } } 

you seem trying read file carrying called bom (byte ordering mark).

test such prefixes , if around used potenial info draw it, go on , read file, interpreting boms indicates.

the sequence \357 \273 \277 indicates utf-8 following. not need take byte-ordering account, byte unit such files.

more on various existing boms here: http://en.wikipedia.org/wiki/byte_order_mark#representations_of_byte_order_marks_by_encoding


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -