From 5ba7b3135775bda3bb05903b9639647d5cf9066f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Tue, 22 Jan 2019 00:00:00 +0000 Subject: [PATCH] count: generalize max --- userland/count.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/userland/count.c b/userland/count.c index e6a6082..9a29b32 100644 --- a/userland/count.c +++ b/userland/count.c @@ -1,11 +1,18 @@ +#include #include +#include #include -int main(void) { - int i = 0; - while (1) { - printf("%d\n", i); - i++; - sleep(1); - } +int main(int argc, char **argv) { + unsigned long i = 0, max; + if (argc > 1) { + max = strtoul(argv[1], NULL, 10); + } else { + max = ULONG_MAX; + } + while (i < max) { + printf("%lu\n", i); + i++; + sleep(1); + } }