summaryrefslogtreecommitdiffstats
path: root/src/cumsum.c
diff options
context:
space:
mode:
authorDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2025-09-19 16:54:04 -0400
committerDouglas B. Rumbaugh <doug@douglasrumbaugh.com>2025-09-19 16:55:35 -0400
commit292c5fb43f5402bcbd2c26607543f5bfc815e8e5 (patch)
tree01f558b6b2ede7ea0786f1366a56fec873456ccc /src/cumsum.c
parent44aa2be93d86e5bac3768962f4fea14a4b3778d3 (diff)
downloadmath-utils-292c5fb43f5402bcbd2c26607543f5bfc815e8e5.tar.gz
Portability and Bugfixes
Diffstat (limited to 'src/cumsum.c')
-rw-r--r--src/cumsum.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/cumsum.c b/src/cumsum.c
index 99c7651..ff8ab73 100644
--- a/src/cumsum.c
+++ b/src/cumsum.c
@@ -44,7 +44,7 @@ static int parse_options(int argc, char *const *argv) {
case 'w':
ARG_WINDOW_SIZE = atol(optarg);
if (ARG_WINDOW_SIZE <= 0) {
- fprintf(stderr, "Error: invalid window size: %lld. Must be > 0.\n",
+ fprintf(stderr, "Error: invalid window size: %" PRId64 ". Must be > 0.\n",
ARG_WINDOW_SIZE);
error = true;
break;
@@ -95,9 +95,9 @@ void print_sum(Number sum) {
if (ARG_FP_INPUT) {
fprintf(stdout, "%lf\n", sum.d);
} else if (ARG_UINT_INPUT) {
- fprintf(stdout, "%lld\n", sum.u);
+ fprintf(stdout, "%" PRIu64 "\n", sum.u);
} else {
- fprintf(stdout, "%lld\n", sum.i);
+ fprintf(stdout, "%" PRId64 "\n", sum.i);
}
}
@@ -108,7 +108,7 @@ static int get_next_number(FILE *file, Number *num) {
int rc = fscanf(file, "%511s", buffer);
if (rc == EOF) {
return 0;
- } else if (rc != -1) {
+ } else if (rc != 1) {
return -1;
}
@@ -152,7 +152,7 @@ void accumulate_number(Number *sum, Number num) {
void print_buffer_sum() {
Number sum = {};
- for (size_t i = 0; i < ARG_WINDOW_SIZE; i++) {
+ for (int64_t i = 0; i < ARG_WINDOW_SIZE; i++) {
accumulate_number(&sum, window_buffer[i]);
}
print_sum(sum);
@@ -191,7 +191,6 @@ static int process_data(FILE *file) {
print_sum(sum);
}
-process_data_end:
return rc;
}
@@ -227,7 +226,6 @@ int main(int argc, char **argv) {
rc = EXIT_FAILURE;
}
-close_file:
if (input_file != stdin) {
fclose(input_file);
}