From 8092f4c334db547ced59d6f439b558dad35e1ab2 Mon Sep 17 00:00:00 2001 From: Mike Vink Date: Fri, 14 Jun 2024 09:23:32 +0200 Subject: commit for once --- 3/10_control_and_data/01_echo.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 3/10_control_and_data/01_echo.c (limited to '3/10_control_and_data/01_echo.c') diff --git a/3/10_control_and_data/01_echo.c b/3/10_control_and_data/01_echo.c new file mode 100644 index 0000000..8ef71e2 --- /dev/null +++ b/3/10_control_and_data/01_echo.c @@ -0,0 +1,24 @@ +#include + +char* gets(char *s) { + int c; + char *dest = s; + while ((c = getchar()) != '\n' && c != EOF) { + *dest++ = c; + } + if ( c == EOF && dest == s) { + return NULL; + } + *dest++ = '\0'; + return s; +} + +void echo() { + char buf[8]; + gets(buf); + puts(buf); +} + +int main(void) { + echo(); +} -- cgit v1.2.3