| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #define IMP
- #include "../file.h"
- size_t cstr_char_count(const char *cstr, char c);
- int cmp_sort(const void *this, const void *other);
- int
- main(int argc, char *argv[])
- {
- enum file_err ferr;
- long res = 0;
- char *raw_input = NULL;
- size_t raw_input_size = 0;
- raw_input = (char *) file_read_all("./input.txt",
- &raw_input_size,
- &ferr);
- if ( ferr != FILE_ERR_OK ) {
- fprintf(stderr, "Failed to open file: %s\n",
- file_err_to_cstr(ferr));
- exit(EXIT_FAILURE);
- }
- if ( argc == 1 ) {
- char *cstr = raw_input;
- loop:
- switch ( *(cstr++) ) {
- case '\0':
- goto exit_loop;
- case '(':
- ++res;
- break;
- case ')':
- --res;
- break;
- }
- goto loop;
- exit_loop:
- ;
- } else {
- }
- printf("Result: %ld\n", res);
- free(raw_input);
- (void) argc; (void) argv;
- return 0;
- }
- size_t
- cstr_char_count(const char *cstr, char c)
- {
- size_t ret = 0;
- while ( *cstr != '\0' ) {
- ret += ( *cstr == c );
- cstr++;
- }
- return ret;
- }
- int
- cmp_sort(const void *this, const void *other)
- {
- long this_ = *((long*) this);
- long other_ = *((long*) other);
- return (int) (this_ - other_);
- }
|