From 5381667a0cee1de7b2064343f5d782173ce5a8e6 Mon Sep 17 00:00:00 2001 From: Peter Ludemann Date: Sat, 11 Jul 2026 16:55:05 -0700 Subject: [PATCH] DOC: update sample calc.c to match doc --- man/calc.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/man/calc.c b/man/calc.c index 4ed5c31b67..b3f2b63b82 100644 --- a/man/calc.c +++ b/man/calc.c @@ -1,19 +1,30 @@ +#include +#include #include #include -#define MAXLINE 1024 - int main(int argc, char **argv) -{ char expression[MAXLINE]; - char *e = expression; +{ char *expression; char *program = argv[0]; - char *plav[2]; - int n; - /* combine all the arguments in a single string */ + if ( argc < 2 ) + { fprintf(stderr, "Usage: %s expression\n", program); + exit(1); + } + + /* Determine length of joined arguments */ + size_t len = 1 + argc - 2; + for(int n=1; n