diff options
Diffstat (limited to 'cescape.c')
-rw-r--r-- | cescape.c | 21 |
1 files changed, 21 insertions, 0 deletions
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 <tomasz@kramkow.ski> +// SPDX-LicenseIdentifier: GPL-3.0-or-later + +// A tool to produce escaped C strings. +// Only escapes tabs, newlines, double quotes and backslashes. + +#include <stdio.h> + +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; + } + } +} |