diff options
Diffstat (limited to 'progs')
-rw-r--r-- | progs/echo/echo.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/progs/echo/echo.c b/progs/echo/echo.c new file mode 100644 index 0000000..86fe083 --- /dev/null +++ b/progs/echo/echo.c @@ -0,0 +1,26 @@ +#include <stdio.h> +#include <string.h> + +int main(int argc, char *argv[]) { + int newline = 1; // Default to printing a newline + int start = 1; // Start argument index + + if (argc > 1 && strcmp(argv[1], "-n") == 0) { + newline = 0; + start = 2; + } + + for (int i = start; i < argc; i++) { + printf("%s", argv[i]); + if (i < argc - 1) { + printf(" "); + } + } + + if (newline) { + printf("\n"); + } + + return 0; +} + |