From 718829335b85ce5d5a9bc1da57f9473b2beb0236 Mon Sep 17 00:00:00 2001 From: Yaossg Date: Tue, 11 Mar 2025 21:38:48 +0800 Subject: [PATCH] fix echo for EOF ending --- boot.c | 6 +++--- demo/empty.c | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 demo/empty.c diff --git a/boot.c b/boot.c index 03ecc60..16ccf14 100644 --- a/boot.c +++ b/boot.c @@ -39,12 +39,12 @@ int echo_size; int readchar() { int ch = getchar(); - if (ch != '\n') { - echo_buffer[echo_size++] = ch; - } else { + if (ch == '\n' || ch == -1) { echo_buffer[echo_size++] = 0; printf("#@%s\n", echo_buffer); echo_size = 0; + } else { + echo_buffer[echo_size++] = ch; } return ch; } diff --git a/demo/empty.c b/demo/empty.c new file mode 100644 index 0000000..c272dab --- /dev/null +++ b/demo/empty.c @@ -0,0 +1 @@ +int main() {} \ No newline at end of file