-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdumpFile.c
40 lines (37 loc) · 960 Bytes
/
dumpFile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// dump a binary data file with signed bytes
// stop after kMaxBytesToDump
// gcc dumpFile.c -o dumpFile
// ./dumpFile /media/marksp/DeveloperDisk/Audio/am_out.dat >plotme.txt
//
// gnuplot
// gnuplot> plot "plotme.txt"
#include <stdio.h>
#include <stdlib.h>
const long kMaxBytesToDump = 100000;
int main(int argc, const char * argv[]) {
if(argc < 2) {
printf("Utility to dump signed byte binary files\n");
printf("Usage %s <fileName>\n", argv[0]);
exit(0);
}
const char *inFileName = argv[1];
//printf("dumping: %s\n", inFileName);
FILE *infp = fopen(inFileName, "rb");
if(infp) {
// get the length of the file
fseek(infp, 0L, SEEK_END);
long length = ftell(infp);
// seek back to the start
fseek(infp, 0L, SEEK_SET);
if(length > kMaxBytesToDump) {
length = kMaxBytesToDump;
}
char c;
for(long position = 0; position < length; position++) {
c = getc(infp);
printf("%d\n", (int)c);
}
fclose(infp);
}
return 0;
}