C语言学习:枚举
1 #include <io_utils.h> 2 3 typedef enum FileFormat { 4 PNG, JPEG = 10, BMP = 20, UNKNOWN 5 } FileFormat; 6 7 FileFormat GuessFormat(char *file_path) { 8 FILE *file = fopen(file_path, "rb"); 9 FileFormat file_format = UNKNOWN; 10 if (file) { 11 char buffer[8] = {0}; 12 size_t bytes_count = fread(buffer, 1, 8, file); 13 if (bytes_count == 8) { 14 // bmp: 42 4D 15 // png: 89 50 4E 47 0D 0A 1A 0A 16 // jpeg: FF D8 FF E0 17 if (*((short *) buffer) == 0x4D42) { 18 file_format = BMP; 19 } else if(*((long long *) buffer) == 0x0A1A0A0D474E5089) { 20 file_format = PNG; 21 } else if(*((int *) buffer) == 0xE0FFD8FF) { 22 file_format = JPEG; 23 } 24 } 25 fclose(file); 26 } 27 return file_format; 28 } 29 30 int main() { 31 FileFormat file_format = PNG; 32 FileFormat file_format_1 = 1; 33 34 PRINT_INT(GuessFormat("images/c.png")); 35 PRINT_INT(GuessFormat("images/c.jpeg")); 36 PRINT_INT(GuessFormat("images/c.bmp")); 37 PRINT_INT(GuessFormat("images/c.webp")); 38 39 return 0; 40 }
怎么设置代码的执行路径