Created
January 17, 2018 05:25
-
-
Save sasaki-shigeo/c3470c14e30127b6ac9d4c795cd8a216 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| #include <stdio.h> | |
| int main(int argc, char *argv[]) { | |
| FILE *fp; | |
| if (argc < 2) { | |
| fp = stdin; | |
| } | |
| else { | |
| fp = fopen(argv[1], "r"); | |
| if (fp == NULL) { | |
| fprintf(stderr, "cannot open: %s\n", argv[1]); | |
| exit(1); | |
| } | |
| } | |
| char buf[BUFSIZ]; | |
| size_t sz; | |
| int seq = 0; | |
| while ((sz = fread(buf, 1, BUFSIZ, fp)) != 0) { | |
| for (int i = 0; i < sz; i++) { | |
| if ((seq & 0x0f) == 0) { | |
| printf("%04X : ", seq); | |
| } | |
| printf("%02X ", buf[i] & 0xff); | |
| seq++; | |
| if ((seq & 0x0f) == 0) { | |
| putchar('\n'); | |
| } | |
| } | |
| } | |
| putchar('\n'); | |
| fflush(stdout); | |
| if (feof(fp)) { | |
| return 0; | |
| } | |
| else { | |
| return ferror(fp); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment