Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
axelo committed Dec 5, 2023
1 parent b454760 commit 12f6ed7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
23 changes: 18 additions & 5 deletions compile-and-run.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
set -euo pipefail

DAY="$1"
INPUT="$2"

if [[ -z ${2-} ]]; then
INPUT="${1:0:-1}.input"
else
INPUT=$2
fi

FLAGS="-Ofast \
-Wunused-but-set-variable \
-Wunused-parameter \
-Wunused-macros"

if [[ -v D ]]; then
FLAGS="-O0 \
-Wno-unused-function \
-Wno-unused-variable"
fi

mkdir -p build

Expand All @@ -19,10 +35,7 @@ clang \
-Wsign-compare \
-Wswitch-enum \
-Wno-gnu-binary-literal \
-Wunused-variable \
-Wunused-function \
-Wunused-but-set-variable \
-Wunused-parameter \
${=FLAGS} \
-std=c17 \
--debug \
-o "./build/$DAY" \
Expand Down
3 changes: 2 additions & 1 deletion template.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
int main(void) {
char *line = NULL;
size_t ngetline = 0;

int nchars = 0;

while ((nchars = (int)getline(&line, &ngetline, stdin)) > 0) {
if (line[nchars - 1] == '\n') line[--nchars] = '\0';
if (line[nchars - 1] == '\n') line[--nchars] = 0;

printf("line: %s\n", line);
}
Expand Down

0 comments on commit 12f6ed7

Please sign in to comment.