main.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #define IMP
  5. #include "../file.h"
  6. size_t cstr_char_count(const char *cstr, char c);
  7. int cmp_sort(const void *this, const void *other);
  8. int
  9. main(int argc, char *argv[])
  10. {
  11. enum file_err ferr;
  12. long res = 0;
  13. char *raw_input = NULL;
  14. size_t raw_input_size = 0;
  15. raw_input = (char *) file_read_all("./input.txt",
  16. &raw_input_size,
  17. &ferr);
  18. if ( ferr != FILE_ERR_OK ) {
  19. fprintf(stderr, "Failed to open file: %s\n",
  20. file_err_to_cstr(ferr));
  21. exit(EXIT_FAILURE);
  22. }
  23. if ( argc == 1 ) {
  24. char *cstr = raw_input;
  25. loop:
  26. switch ( *(cstr++) ) {
  27. case '\0':
  28. goto exit_loop;
  29. case '(':
  30. ++res;
  31. break;
  32. case ')':
  33. --res;
  34. break;
  35. }
  36. goto loop;
  37. exit_loop:
  38. ;
  39. } else {
  40. }
  41. printf("Result: %ld\n", res);
  42. free(raw_input);
  43. (void) argc; (void) argv;
  44. return 0;
  45. }
  46. size_t
  47. cstr_char_count(const char *cstr, char c)
  48. {
  49. size_t ret = 0;
  50. while ( *cstr != '\0' ) {
  51. ret += ( *cstr == c );
  52. cstr++;
  53. }
  54. return ret;
  55. }
  56. int
  57. cmp_sort(const void *this, const void *other)
  58. {
  59. long this_ = *((long*) this);
  60. long other_ = *((long*) other);
  61. return (int) (this_ - other_);
  62. }