From 70b0b72b1649e830f2135051b6420dce4fcaacc8 Mon Sep 17 00:00:00 2001 From: dtb Date: Fri, 21 Oct 2022 19:59:23 -0400 Subject: [PATCH] prompt(1) --- echo/Makefile | 7 +++++-- echo/echo.c | 15 ++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/echo/Makefile b/echo/Makefile index b8c8c33..d82b837 100644 --- a/echo/Makefile +++ b/echo/Makefile @@ -1,10 +1,13 @@ -TARGETS = echo +TARGETS = echo prompt all: $(TARGETS) -%: %.c +echo: echo.c $(CC) -o $@ $@.c +prompt: echo.c + $(CC) -DPROMPT -o $@ echo.c + clean: rm -f $(TARGETS) diff --git a/echo/echo.c b/echo/echo.c index 6edc29a..36bf746 100644 --- a/echo/echo.c +++ b/echo/echo.c @@ -8,13 +8,18 @@ int main(int argc, char **argv){ if(*argv == NULL) goto blank; - while(*++argv != NULL){ - for(i = 0; argv[0][i] != '\0'; ++i); - write(1, *argv, i); + ++argv; - if(*(argv+1) != NULL) + while(--argc){ + for(i = 0; argv[0][i] != '\0'; ++i); + write(1, *(argv++), i); + if(argc > 1) write(1, " ", 1); } -blank: write(1, "\n", 1); + +blank: +#ifndef PROMPT + write(1, "\n", 1); +#endif return EX_OK; }