fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<getopt.h>
  5. #include<regex.h>
  6.  
  7. #define no_argument 0
  8. #define required_argument 1
  9. #define SIZE 10
  10. #define COMMAND_SIZE 50
  11. #define GROUPS 1
  12. #define NEW_FILE_NAME "./out.BMP"
  13. #define HELP_MESSAGE "Course work for option 4.6, created by Pyankov Mikhail\nflags:\n\n--line :\n--start %d.%d --end %d.%d --color %d.%d.%d --thickness %d\n\n--inverse_circle :\n--center %d.%d --radius %d\n\n--trim :\n--left_up %d.%d --right_down %d.%d"
  14. #define DEFAULT_MESSAGE "Use flags, for information put flag -h"
  15.  
  16. #define REG_COORDS "^-?[0-9]+\\.-?[0-9]+$"
  17. #define REG_COORDS_EXTENDED "^-?[0-9]+\\.-?[0-9]+(\\.-?[0-9]+)+$"
  18.  
  19. #define REG_LINE_COLOR "^[0-9]+\\.[0-9]+\\.[0-9]+$"
  20. #define REG_LINE_COLOR_EXTENDED "^[0-9]+\\.[0-9]+\\.[0-9]+(\\.-?[0-9]+)+$"
  21.  
  22. #define REG_ONE_ARG "^[0-9]+$"
  23. #define REG_ONE_ARG_EXTENDED "^[0-9]+(\\.-?[0-9]+)+$"
  24.  
  25. #define FILE_NAME "[0-9A-z~@#\\$\\^-_\\(\\)\\{\\}'`]+\\.[0-9A-z~@#\\$\\^-_\\(\\)\\{\\}'`]+$"
  26.  
  27. #define INVALID_COMMAND "Invalid command!"
  28. #define EXTENDED_COMMAND_1 "Too much args for "
  29. #define EXTENDED_COMMAND_2 " flag, only first will be write!"
  30.  
  31. #define LINE_COMMAND_ERROR "Missed args for --line flag!"
  32. #define INVERSE_CIRCLE_COMMAND_ERROR "Missed args for --inverse_circle flag!"
  33. #define TRIM_COMMAND_ERROR "Missed args for --trim flag!"
  34.  
  35. #define FILE_NAME_FORGOTTEN "Put file_name!"
  36. #define FILE_NAME_ERROR "There is no file with that name!"
  37. #define FILE_TYPE_ERROR "File corrupted!"
  38. #define OUTPUT_FILE_ERROR "Output file name error, default name will be out.BMP!"
  39. #define SAME_INP_OUT_FILES "Input and output files are same!"
  40. #define ERROR_CODE 40
  41.  
  42. #pragma pack (push, 1)
  43.  
  44. typedef struct {
  45. unsigned short signature;
  46. unsigned int filesize;
  47. unsigned short reserved1;
  48. unsigned short reserved2;
  49. unsigned int pixelArrOffset;
  50. } BitmapFileHeader;
  51.  
  52. typedef struct {
  53. unsigned int headerSize;
  54. unsigned int width;
  55. unsigned int height;
  56. unsigned short planes;
  57. unsigned short bitsPerPixel;
  58. unsigned int compression;
  59. unsigned int imageSize;
  60. unsigned int xPixelsPerMeter;
  61. unsigned int yPixelsPerMeter;
  62. unsigned int colorsInColorTable;
  63. unsigned int importantColorCount;
  64. } BitmapInfoHeader;
  65.  
  66. typedef struct {
  67. unsigned char b;
  68. unsigned char g;
  69. unsigned char r;
  70. } Rgb;
  71.  
  72. #pragma pack(pop)
  73.  
  74. void print_file_header(BitmapFileHeader header)
  75. {
  76. printf("signature:\t%x (%hu)\n", header.signature, header.signature);
  77. printf("filesize:\t%x (%u)\n", header.filesize, header.filesize);
  78. printf("reserved1:\t%x (%hu)\n", header.reserved1, header.reserved1);
  79. printf("reserved2:\t%x (%hu)\n", header.reserved2, header.reserved2);
  80. printf("pixelArrOffset:\t%x (%u)\n", header.pixelArrOffset, header.pixelArrOffset);
  81. }
  82.  
  83. void print_info_header(BitmapInfoHeader header)
  84. {
  85. printf("headerSize:\t%x (%u)\n", header.headerSize, header.headerSize);
  86. printf("width: \t%x (%u)\n", header.width, header.width);
  87. printf("height: \t%x (%u)\n", header.height, header.height);
  88. printf("planes: \t%x (%hu)\n", header.planes, header.planes);
  89. printf("bitsPerPixel:\t%x (%hu)\n", header.bitsPerPixel, header.bitsPerPixel);
  90. printf("compression:\t%x (%u)\n", header.compression, header.compression);
  91. printf("imageSize:\t%x (%u)\n", header.imageSize, header.imageSize);
  92. printf("xPixelsPerMeter:\t%x (%u)\n", header.xPixelsPerMeter, header.xPixelsPerMeter);
  93. printf("yPixelsPerMeter:\t%x (%u)\n", header.yPixelsPerMeter, header.yPixelsPerMeter);
  94. printf("colorsInColorTable:\t%x (%u)\n", header.colorsInColorTable, header.colorsInColorTable);
  95. printf("importantColorCount:\t%x (%u)\n", header.importantColorCount, header.importantColorCount);
  96. }
  97.  
  98. int extend_command_message(char* command)
  99. {
  100. char* message = strdup(EXTENDED_COMMAND_1);
  101. strcat(message, command);
  102. strcat(message, EXTENDED_COMMAND_2);
  103. puts(message);
  104. }
  105.  
  106. int check_coords_arg(char* optarg)
  107. {
  108. regex_t regex_compiled;
  109. regmatch_t group_array[GROUPS];
  110.  
  111. regcomp(&regex_compiled, REG_COORDS, REG_EXTENDED);
  112. if(regexec(&regex_compiled, optarg, GROUPS, group_array, 0) == 0)
  113. return 1;
  114. regcomp(&regex_compiled, REG_COORDS_EXTENDED, REG_EXTENDED);
  115. if(regexec(&regex_compiled, optarg, GROUPS, group_array, 0) == 0)
  116. return 2;
  117. return 0;
  118. }
  119.  
  120. int check_one_arg(char* optarg)
  121. {
  122. regex_t regex_compiled;
  123. regmatch_t group_array[GROUPS];
  124.  
  125. regcomp(&regex_compiled, REG_ONE_ARG, REG_EXTENDED);
  126. if(regexec(&regex_compiled, optarg, GROUPS, group_array, 0) == 0)
  127. return 1;
  128. regcomp(&regex_compiled, REG_ONE_ARG_EXTENDED, REG_EXTENDED);
  129. if(regexec(&regex_compiled, optarg, GROUPS, group_array, 0) == 0)
  130. return 2;
  131. return 0;
  132. }
  133.  
  134. int check_color_arg(char* optarg)
  135. {
  136. regex_t regex_compiled;
  137. regmatch_t group_array[GROUPS];
  138.  
  139. regcomp(&regex_compiled, REG_LINE_COLOR, REG_EXTENDED);
  140. if(regexec(&regex_compiled, optarg, GROUPS, group_array, 0) == 0)
  141. return 1;
  142. regcomp(&regex_compiled, REG_LINE_COLOR_EXTENDED, REG_EXTENDED);
  143. if(regexec(&regex_compiled, optarg, GROUPS, group_array, 0) == 0)
  144. return 2;
  145. return 0;
  146. }
  147.  
  148. int check_bmp(char* file_name)
  149. {
  150. FILE *f = fopen(file_name, "rb");
  151. BitmapFileHeader bmfh;
  152. BitmapInfoHeader bmif;
  153. fread(&bmfh, 1, sizeof(BitmapFileHeader), f);
  154. fread(&bmif, 1, sizeof(BitmapInfoHeader), f);
  155. if((bmfh.signature == 19778 || bmfh.signature == 16706 || bmfh.signature == 674115 || bmfh.signature == 675907 || bmfh.signature == 672585 || bmfh.signature == 676944)
  156. && bmif.bitsPerPixel == 24 && bmif.compression == 0);
  157. return 1;
  158. return 0;
  159. }
  160.  
  161. int check_file_name(char* file_name)
  162. {
  163. FILE *f = fopen(file_name, "rb");
  164. if(f == NULL)
  165. return 0;
  166. return 1;
  167. }
  168.  
  169. int check_file_str(char* file_name)
  170. {
  171. regex_t regex_compiled;
  172. regmatch_t group_array[GROUPS];
  173.  
  174. regcomp(&regex_compiled, FILE_NAME, REG_EXTENDED);
  175. if(regexec(&regex_compiled, file_name, GROUPS, group_array, 0) == 0)
  176. return 1;
  177. return 0;
  178. }
  179.  
  180. Rgb** read_bmp(char* file_name, BitmapFileHeader* bmfh, BitmapInfoHeader* bmif)
  181. {
  182. FILE *f = fopen(file_name, "rb");
  183. fread(bmfh, 1, sizeof(BitmapFileHeader), f);
  184. fread(bmif, 1, sizeof(BitmapInfoHeader), f);
  185. unsigned int H = bmif->height;
  186. unsigned int W = bmif->width;
  187. Rgb** arr = malloc(H * sizeof(Rgb*));
  188. for(int i = 0; i < H; i++)
  189. {
  190. arr[i] = malloc(W * sizeof(Rgb) + (W * 3) % 4);
  191. fread(arr[i], 1, W * sizeof(Rgb) + (W * 3) % 4,f);
  192. }
  193. fclose(f);
  194. return arr;
  195. }
  196.  
  197. void set_pixel(Rgb** arr, int x, int y, int* color, int H, int W)
  198. {
  199. if(x >= H || x < 0 || y >= W || y < 0)
  200. return;
  201. arr[x][y].r = *(color);
  202. arr[x][y].g = *(color + 1);
  203. arr[x][y].b = *(color + 2);
  204. }
  205.  
  206. void draw_line(Rgb** arr, int H, int W, int x0, int y0, int x1, int y1, int thickness, int* color)
  207. {
  208. if(thickness <=0)
  209. return;
  210. for(int i = 0; i < thickness; i++)
  211. {
  212. int dx = (x1 - x0 >= 0 ? 1 : -1);
  213. int dy = (y1 - y0 >= 0 ? 1 : -1);
  214. int lengthX = abs(x1 - x0);
  215. int lengthY = abs(y1 - y0);
  216. int length = (lengthX - lengthY > 0 ? lengthX : lengthY);
  217. if (length == 0)
  218. set_pixel(arr, x0+i, y0, color, H, W);
  219.  
  220. int x = x0+i;
  221. int y = y0;
  222. if(lengthY <= lengthX)
  223. {
  224. int d = -lengthX;
  225. length++;
  226. while (length--)
  227. {
  228. set_pixel(arr, x, y, color, H, W);
  229. x += dx;
  230. d += 2 * lengthY;
  231. if(d > 0)
  232. {
  233. d -= 2 * lengthX;
  234. y += dy;
  235. }
  236. }
  237. }
  238. else
  239. {
  240. int d = -lengthY;
  241. length++;
  242. while (length--)
  243. {
  244. set_pixel(arr, x, y, color, H, W);
  245. y += dy;
  246. d += 2 * lengthX;
  247. if(d > 0)
  248. {
  249. d -= 2 * lengthY;
  250. x += dx;
  251. }
  252. }
  253. }
  254. }
  255. }
  256.  
  257. int circle_func(int x, int y, int x0, int y0, int r)
  258. {
  259. return ((x - x0) * (x - x0) + (y - y0) * (y - y0)) < (r*r);
  260. }
  261.  
  262. void invert_circle(Rgb** arr, int H, int W, int x0, int y0, int r)
  263. {
  264. for(int i = 0; i < H; i++)
  265. {
  266. for(int j = 0; j < W; j++)
  267. {
  268. if(circle_func(i, j, x0, y0, r))
  269. {
  270. int color[3] = {255 - arr[i][j].r, 255 - arr[i][j].g, 255 - arr[i][j].b};
  271. set_pixel(arr, i, j, color, H, W);
  272. }
  273. }
  274. }
  275. }
  276.  
  277. int rectangle_func(int x, int y, int x0, int y0, int x1, int y1)
  278. {
  279. return (x >= x0 && y <= y0) && (x <= x1 && y >= y1);
  280. }
  281.  
  282. Rgb** trim(Rgb** arr, BitmapInfoHeader* bmif, BitmapFileHeader* bmfh, unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1)
  283. {
  284. if(y0 <= y1 || x0 >= x1)
  285. return arr;
  286. int H = bmif->height;
  287. int W = bmif->width;
  288. x1 = x1 < H ? x1 : H;
  289. y0 = y0 < W ? y0 : W;
  290. int new_W = y0 - y1;
  291. int new_H = x1 - x0;
  292. Rgb** new_arr = malloc(new_H * sizeof(Rgb *));
  293. for (int i = 0; i < new_H; i++)
  294. {
  295. new_arr[i] = malloc(new_W * sizeof(Rgb) + (new_W * 3) % 4);
  296. }
  297. for(int i = 0; i < H; i++)
  298. {
  299. for(int j = 0; j < W; j++)
  300. {
  301. if(rectangle_func(i, j, x0, y0, x1, y1))
  302. {
  303. int color[3] = {arr[i][j].r, arr[i][j].g, arr[i][j].b};
  304. set_pixel(new_arr, i - x0, j - y1, color, new_H, new_W);
  305. }
  306. }
  307. }
  308. bmif->height = new_H;
  309. bmif->width = new_W;
  310. bmfh->filesize = bmfh->filesize - (H-new_H)*(W-new_W)*3;
  311. bmif->imageSize = new_H*new_W*3;
  312. return new_arr;
  313. }
  314.  
  315. void write_bmp(char* file_name, Rgb** arr, int H, int W, BitmapFileHeader bmfh, BitmapInfoHeader bmif)
  316. {
  317. FILE *ff = fopen(file_name, "wb");
  318. fwrite(&bmfh, 1, sizeof(BitmapFileHeader), ff);
  319. fwrite(&bmif, 1, sizeof(BitmapInfoHeader), ff);
  320. for(int i = 0; i < H; i++)
  321. {
  322. fwrite(arr[i], 1, W * sizeof(Rgb) + (W * 3) % 4, ff);
  323. }
  324. fclose(ff);
  325. }
  326.  
  327. int main(int argc, char** argv)
  328. {
  329. char* file_name;
  330. int file_name_flag = 0;
  331. char* new_file_name = NEW_FILE_NAME;
  332.  
  333. BitmapFileHeader bmfh;
  334. BitmapInfoHeader bmif;
  335. Rgb** array;
  336.  
  337. char *opts = "hls:e:c:t:IC:r:TL:R:o:i:f";
  338. int longidx;
  339. static struct option longopts[] =
  340. {
  341. {"help", no_argument, NULL, 'h'},
  342. {"line", no_argument, NULL, 'l'},
  343. {"start", required_argument, NULL, 's'},
  344. {"end", required_argument, NULL, 'e'},
  345. {"color", required_argument, NULL, 'c'},
  346. {"thickness", required_argument, NULL, 't'},
  347. {"inverse_circle", no_argument, NULL, 'I'},
  348. {"center", required_argument, NULL, 'C'},
  349. {"radius", required_argument, NULL, 'r'},
  350. {"trim", no_argument, NULL, 'T'},
  351. {"left_up", required_argument, NULL, 'L'},
  352. {"right_down", required_argument, NULL, 'R'},
  353. {"info", no_argument, NULL, 'f'},
  354. {"output", required_argument, NULL, 'o'},
  355. {"input", required_argument, NULL, 'i'},
  356. {NULL, no_argument, NULL, 0 }
  357. };
  358.  
  359. int opt = getopt_long(argc, argv, opts, longopts, &longidx);
  360.  
  361. if(argc == 1)
  362. {
  363. puts(DEFAULT_MESSAGE);
  364. exit(0);
  365. }
  366.  
  367. int info_flag = 0;
  368.  
  369. int x0,y0,x1,y1,thickness;
  370. int color[3];
  371. int line_flag = 0; int start_flag = 0; int end_flag = 0; int thickness_flag = 0; int color_flag = 0;
  372.  
  373. int xc,yc,rad;
  374. int center_flag = 0; int rag_flag = 0; int inverse_circle_flag = 0;
  375.  
  376. int xl,yl,xr,yr;
  377. int left_flag = 0; int right_flag = 0; int trim_flag = 0;
  378.  
  379. while(opt != -1)
  380. {
  381. switch (opt)
  382. {
  383. case('h'):
  384. {
  385. puts(HELP_MESSAGE);
  386. exit(0);
  387. }
  388. case('f'):
  389. {
  390. info_flag = 1;
  391. break;
  392. }
  393. case('i'):
  394. {
  395. file_name_flag = 1;
  396. file_name = optarg;
  397. break;
  398. }
  399. case('o'):
  400. {
  401. if(check_file_str(optarg))
  402. new_file_name = optarg;
  403. else
  404. puts(OUTPUT_FILE_ERROR);
  405. break;
  406. }
  407. case('l'):
  408. {
  409. line_flag = 1;
  410. break;
  411. }
  412. case('s'):
  413. {
  414. if(line_flag)
  415. {
  416. if(check_coords_arg(optarg))
  417. sscanf(optarg, "%d.%d", &x0, &y0);
  418. if(check_coords_arg(optarg) == 2)
  419. extend_command_message("--start");
  420. if(!check_coords_arg(optarg))
  421. {
  422. puts(INVALID_COMMAND);
  423. exit(ERROR_CODE);
  424. }
  425. start_flag = 1;
  426. }
  427. break;
  428. }
  429. case('e'):
  430. {
  431. if(line_flag)
  432. {
  433. if(check_coords_arg(optarg))
  434. sscanf(optarg, "%d.%d", &x1, &y1);
  435. if(check_coords_arg(optarg) == 2)
  436. extend_command_message("--end");
  437. if(!check_coords_arg(optarg))
  438. {
  439. puts(INVALID_COMMAND);
  440. exit(ERROR_CODE);
  441. }
  442. end_flag = 1;
  443. }
  444. break;
  445. }
  446. case('c'):
  447. {
  448. if(line_flag)
  449. {
  450. if(check_color_arg(optarg))
  451. sscanf(optarg, "%d.%d.%d", &color[0], &color[1], &color[2]);
  452. if(check_color_arg(optarg) == 2)
  453. extend_command_message("--color");
  454. if(!check_color_arg(optarg) || (color[0] > 255 || color[1] > 255 || color[2] > 255))
  455. {
  456. puts(INVALID_COMMAND);
  457. exit(ERROR_CODE);
  458. }
  459. color_flag = 1;
  460. }
  461. break;
  462. }
  463. case('t'):
  464. {
  465. if(line_flag)
  466. {
  467. if(check_one_arg(optarg))
  468. sscanf(optarg, "%d", &thickness);
  469. if(check_one_arg(optarg) == 2)
  470. extend_command_message("--thickness");
  471. if(!check_one_arg(optarg))
  472. {
  473. puts(INVALID_COMMAND);
  474. exit(ERROR_CODE);
  475. }
  476. thickness_flag = 1;
  477. }
  478. break;
  479. }
  480. case('I'):
  481. {
  482. inverse_circle_flag = 1;
  483. break;
  484. }
  485. case('C'):
  486. {
  487. if(inverse_circle_flag)
  488. {
  489. if(check_coords_arg(optarg))
  490. sscanf(optarg, "%d.%d", &xc, &yc);
  491. if(check_coords_arg(optarg) == 2)
  492. extend_command_message("--center");
  493. if(!check_coords_arg(optarg))
  494. {
  495. puts(INVALID_COMMAND);
  496. exit(ERROR_CODE);
  497. }
  498. center_flag = 1;
  499. }
  500. break;
  501. }
  502. case('r'):
  503. {
  504. if(inverse_circle_flag)
  505. {
  506. if(check_one_arg(optarg))
  507. sscanf(optarg, "%d", &rad);
  508. if(check_one_arg(optarg) == 2)
  509. extend_command_message("--radius");
  510. if(!check_one_arg(optarg))
  511. {
  512. puts(INVALID_COMMAND);
  513. exit(ERROR_CODE);
  514. }
  515. rag_flag = 1;
  516. }
  517. break;
  518. }
  519. case('T'):
  520. {
  521. trim_flag = 1;
  522. break;
  523. }
  524. case('L'):
  525. {
  526. if(trim_flag)
  527. {
  528. if(check_coords_arg(optarg))
  529. sscanf(optarg, "%d.%d", &xl, &yl);
  530. if(check_coords_arg(optarg) == 2)
  531. extend_command_message("--left_up");
  532. if(!check_coords_arg(optarg))
  533. {
  534. puts(INVALID_COMMAND);
  535. exit(ERROR_CODE);
  536. }
  537. left_flag = 1;
  538. }
  539. break;
  540. }
  541. case('R'):
  542. {
  543. if(trim_flag)
  544. {
  545. if(check_coords_arg(optarg))
  546. sscanf(optarg, "%d.%d", &xr, &yr);
  547. if(check_coords_arg(optarg) == 2)
  548. extend_command_message("--right_down");
  549. if(!check_coords_arg(optarg))
  550. {
  551. puts(INVALID_COMMAND);
  552. exit(ERROR_CODE);
  553. }
  554. right_flag = 1;
  555. }
  556. break;
  557. }
  558. default:
  559. {
  560. puts(INVALID_COMMAND);
  561. exit(ERROR_CODE);
  562. }
  563. }
  564. opt = getopt_long(argc, argv, opts, longopts, &longidx);
  565. }
  566.  
  567. if(!file_name_flag)
  568. {
  569. puts(argv[argc-1]);
  570. if(check_file_str(argv[argc-1]))
  571. file_name = argv[argc-1];
  572. else
  573. {
  574. puts(FILE_NAME_FORGOTTEN);
  575. exit(ERROR_CODE);
  576. }
  577. }
  578. if(!strcmp(file_name, new_file_name))
  579. {
  580. puts(SAME_INP_OUT_FILES);
  581. exit(ERROR_CODE);
  582. }
  583. if(!check_file_name(file_name))
  584. {
  585. puts(FILE_NAME_ERROR);
  586. exit(ERROR_CODE);
  587. }
  588. if(!check_bmp(file_name))
  589. {
  590. puts(FILE_TYPE_ERROR);
  591. exit(ERROR_CODE);
  592. }
  593.  
  594. array = read_bmp(file_name, &bmfh, &bmif);
  595.  
  596. if(info_flag)
  597. {
  598. print_file_header(bmfh);
  599. printf("\n");
  600. print_info_header(bmif);
  601. }
  602. if(line_flag)
  603. {
  604. if(start_flag && end_flag && color_flag && thickness_flag)
  605. draw_line(array, bmif.height, bmif.width, x0, y0, x1, y1, thickness, color);
  606. else
  607. {
  608. puts(LINE_COMMAND_ERROR);
  609. exit(ERROR_CODE);
  610. }
  611. }
  612. if(inverse_circle_flag)
  613. {
  614. if(center_flag && rag_flag)
  615. invert_circle(array, bmif.height, bmif.width, xc, yc, rad);
  616. else
  617. {
  618. puts(INVERSE_CIRCLE_COMMAND_ERROR);
  619. exit(ERROR_CODE);
  620. }
  621. }
  622. if(trim_flag)
  623. {
  624. if(left_flag && right_flag)
  625. array = trim(array, &bmif, &bmfh, xl, yl, xr, yr);
  626. else
  627. {
  628. puts(INVERSE_CIRCLE_COMMAND_ERROR);
  629. exit(ERROR_CODE);
  630. }
  631. }
  632.  
  633. write_bmp(new_file_name, array, bmif.height, bmif.width, bmfh, bmif);
  634.  
  635. exit(0);
  636. }
  637.  
Success #stdin #stdout 0s 5280KB
stdin
/*  Berechnung des Hamming-Abstandes zwischen zwei 128-Bit Werten in 	*/
/*	einer Textdatei. 													*/
/*  Die Werte müssen auf einer separaten Zeile gespeichert sein			*/
/* 																		*/
/*	Erstellt: 17.5.2010													*/
/*  Autor: Thomas Scheffler												*/

#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE 32

unsigned Hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}



int main (void)
{
	char hex;
	int i;
	int a[ARRAY_SIZE];
	int b[ARRAY_SIZE];
	int hamDist = 0;
	FILE* fp;
	
	//Arrays mit 0 initialisieren
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
  		a[i] = 0;
  		b[i] = 0;
	}

	
	fp = fopen("hex.txt","r");
	if (fp == NULL) 
	{
		printf("Die Datei hex.txt wurde nicht gefunden!");
		exit(EXIT_FAILURE);
	}

	i=0;
	printf("1.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
        a[i]=strtol(&hex,0,16);
		i++;
    }
	i=0;
	printf("2.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
    	b[i]=strtol(&hex,0,16);
        i++;
    }
	fclose(fp);

	printf("Hamming-Abweichung pro Nibble:\n");
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
		printf ("%i\t%i\t%i\n",a[i],b[i],Hamdist(a[i],b[i]));
		hamDist += Hamdist(a[i],b[i]);
	}
	printf ("\nHamming-Abweichung der Hash-Werte:%d\n",hamDist);
}

stdout
Use flags, for information put flag -h