-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertEndian.cpp
More file actions
53 lines (48 loc) · 1.15 KB
/
convertEndian.cpp
File metadata and controls
53 lines (48 loc) · 1.15 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <cstdio>
int main(int argc, char** argv) {
if (argc == 1) {
fprintf(stderr, "No input file specified\n");
return 1;
}
if (argc == 2) {
fprintf(stderr, "No output file specified\n");
return 1;
}
if (argc > 3) {
fprintf(stderr, "Extraneous arguments\n");
}
char* inFile = argv[1];
char* outFile = argv[2];
FILE* in = NULL;
if ((inFile[0] == '-') && (inFile[1] == 0))
in = stdin;
else
in = fopen(inFile, "rb");
if (in == NULL) {
fprintf(stderr, "Failed to open input file \"%s\"\n", inFile);
return 2;
}
FILE* out = NULL;
if ((outFile[0] == '-') && (outFile[1] == 0))
out = stdout;
else
out = fopen(outFile, "wb");
if (out == NULL) {
fprintf(stderr, "Failed to open output file \"%s\"\n", outFile);
fclose(in);
return 2;
}
while (1==1) {
int c1 = fgetc(in);
if (c1 == EOF)
break;
int c2 = fgetc(in);
if (c2 == EOF)
c2 = 0;
fputc(c2, out);
fputc(c1, out);
}
fclose(in);
fclose(out);
return 0;
}