From 8d51757e02818146b05c805b81e167f118fca7dc Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Tue, 12 Nov 2024 13:36:10 +0000 Subject: The quine --- cescape.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 cescape.c (limited to 'cescape.c') diff --git a/cescape.c b/cescape.c new file mode 100644 index 0000000..3fd5ac2 --- /dev/null +++ b/cescape.c @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: 2024 Tomasz Kramkowski +// SPDX-LicenseIdentifier: GPL-3.0-or-later + +// A tool to produce escaped C strings. +// Only escapes tabs, newlines, double quotes and backslashes. + +#include + +int main(void) +{ + int c; + while (c = getchar(), c != EOF) { + switch (c) { + case '\t': fputs("\\t", stdout); break; + case '\n': fputs("\\n", stdout); break; + case '"': fputs("\\\"", stdout); break; + case '\\': fputs("\\\\", stdout); break; + default: putchar(c); break; + } + } +} -- cgit v1.2.3-54-g00ecf