Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #define INPUT_FILE_NAME "integers.bin"
- #define OUTPUT_FILE_NAME "hex.txt"
- FILE *safeOpenFile(const char *const path, const char *const mode) {
- FILE *file = NULL;
- file = fopen(path, mode);
- if (file == NULL) {
- perror("opening error!");
- exit(EXIT_FAILURE);
- }
- return file;
- }
- void safeCloseFile(FILE *file) {
- if (fclose(file) == EOF) {
- perror(NULL);
- }
- }
- int main(void) {
- FILE *fin = safeOpenFile(INPUT_FILE_NAME, "rb");
- FILE *fout = safeOpenFile(OUTPUT_FILE_NAME, "w");
- for (uint16_t aux; fread(&aux, sizeof(aux), 1, fin) == 1;) {
- fprintf(fout, "%08x\n", aux);
- }
- safeCloseFile(fin);
- safeCloseFile(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement