-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
42 lines (34 loc) · 909 Bytes
/
main.cpp
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
#include <stdio.h>
#include <stdint.h>
#include <arpa/inet.h>
#include "add-nbo.h"
#define BUFFER_SIZE 100
int main(int argc, char *argv[]){
if(argc != 3){
printf("Use: %s <filename> <filename>\n", argv[0]);
return 1;
}
FILE *file1 = fopen(argv[1], "rb");
if(!file1){
printf("Error %s\n", argv[1]);
return 1;
}
FILE *file2 = fopen(argv[2], "rb");
if(!file2){
printf("Error %s\n", argv[2]);
fclose(file1);
return 1;
}
uint8_t buffer[BUFFER_SIZE];
uint32_t a;
uint32_t b;
fread(&a, sizeof(uint32_t), BUFFER_SIZE, file1);
fread(&b, sizeof(uint32_t), BUFFER_SIZE, file2);
uint32_t c = ntohl(a);
uint32_t d = ntohl(b);
uint32_t result = add_nbo(c,d);
printf("%u(0x%x) + %u(0x%x) = %u(0x%x)\n",c,c,d,d,result,result);
fclose(file1);
fclose(file2);
return 0;
}