diff --git a/A0/file b/A0/file index 553c19c..d2e5309 100755 Binary files a/A0/file and b/A0/file differ diff --git a/A0/file.c b/A0/file.c index 9d9d7cc..0106c1d 100644 --- a/A0/file.c +++ b/A0/file.c @@ -9,22 +9,25 @@ enum FileType{ASCII, ISO, UTF, data}; bool is_utf8(FILE* f) { rewind(f); char byte; - bool utf8_byte; - int char_length; + int char_length = -1; for (;;) { if (fread(&byte, 1, 1, f) == 0) { break; } - utf8_byte = true; - for (int j = 0 ; 1 ; j++) { + for (int j = 0 ; j <= 8 ; j++) { if (byte >> 7 == 0) { - char_length = max(j, 1); + char_length = j; break; } byte = byte << 1; } + if (char_length == -1) { + return false; + } for (int i = 1 ; i < char_length ; i++) { - printf("esnathusrcaho"); + if (fread(&byte, 1, 1, f) == 0 || byte >> 6 != 2) { + return false; + } } } return true;