summaryrefslogtreecommitdiff
path: root/3/10_control_and_data/01_echo.c
diff options
context:
space:
mode:
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();
+}