Advertisement
BumbleBritches57

Fopen UTF-8 BOM test

Aug 16th, 2018
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdlib.h>
  4. typedef uint_least8_t UTF8;
  5.  
  6. int main(int argc, const char * argv[]) {
  7.     // insert code here..
  8.     UTF8 *PathWithoutBOM = u8"/PATH/TO/A/TEXT/FILE.TXT";
  9.     UTF8 *PathWithBOM    = u8"\xEF\xBB\xBF/PATH/TO/A/TEXT/FILE.TXT";
  10.    
  11.    
  12.     printf("PathWithoutBOM: %s, Size: %d\n", PathWithoutBOM, strlen(PathWithoutBOM));
  13.     printf("PathWithBOM: %s, Size: %d\n", PathWithBOM, strlen(PathWithBOM));
  14.    
  15.     FILE *FileWithoutBOM = fopen(PathWithoutBOM, "r");
  16.     FILE *FileWithBOM    = fopen(PathWithBOM, "r");
  17.    
  18.     uint8_t *FileWithoutBOMBuffer = calloc(1024, sizeof(UTF8));
  19.     uint8_t *FileWithBOMBuffer    = calloc(1024, sizeof(UTF8));
  20.    
  21.     fread(FileWithoutBOMBuffer, 1, 1024, FileWithoutBOM);
  22.     fread(FileWithBOMBuffer, 1, 1024, FileWithBOM);
  23.    
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement