summaryrefslogtreecommitdiff
path: root/3/10_control_and_data/01_echo.c
blob: 8ef71e2f7333b21762575012568d6fd6c058a2ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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();
}