Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #include <malloc.h>
- #include <string.h>
- char asci[] = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E";
- char
- chr2seg
- (dec, chr)
- int dec;
- char chr;
- {
- /* looks up one character on asci table */
- chr = asci[dec];
- return chr;
- }
- int
- hex2asci
- (hx)
- char *hx;
- {
- int r, j, k;
- // cmp asci tble every 2 chars
- for( k=0; k<127; k++) {
- j = k*2; // nib's are real.. they eat nybles
- r = j+1;
- char nib[1] = "00";
- char m = chr2seg(j, m);
- char a = chr2seg(r, a);
- char t = hx[0];
- char h = hx[1];
- nib[0] = m;
- nib[1] = a;
- if( m == t ) {
- if( a == h ) {
- return k +2;
- }
- }
- }
- return 129;
- }
- void
- main
- (void)
- {
- char *filename = "vba.hex";
- FILE* fh;
- fh = fopen(filename, "r");
- const size_t line_size = 3;
- char* line = malloc(line_size);
- while (fgets(line, line_size, fh) != NULL) {
- printf("%sn", line);
- int r = hex2asci(line);
- /*!!! FIXME!!!! r should be changing, in this case incrementing by one with each line */
- printf("we got %dn", r);
- }
- free(line);
- return;
- }
Add Comment
Please, Sign In to add comment