summaryrefslogtreecommitdiff
path: root/3/10_control_and_data/01_echo.c
diff options
context:
space:
mode:
authorMike Vink <mike@pionative.com>2024-06-14 09:23:32 +0200
committerMike Vink <mike@pionative.com>2024-06-14 09:23:32 +0200
commit8092f4c334db547ced59d6f439b558dad35e1ab2 (patch)
treefa462fa885efea1ec6095d015286998d632c2c3d /3/10_control_and_data/01_echo.c
parentb424517a33bf61aedff29eed74a665402ab496ba (diff)
commit for once
Diffstat (limited to '3/10_control_and_data/01_echo.c')
-rw-r--r--3/10_control_and_data/01_echo.c24
1 files changed, 24 insertions, 0 deletions
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 <stdio.h>
+
+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();
+}