From 1b36028f24290c587cbad5412530b8b1ac91a047 Mon Sep 17 00:00:00 2001 From: Van P Phu Date: Thu, 2 Jun 2016 05:27:59 -0400 Subject: [PATCH] C implementation --- tabs.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tabs.c diff --git a/tabs.c b/tabs.c new file mode 100644 index 0000000..c9c5e1c --- /dev/null +++ b/tabs.c @@ -0,0 +1,32 @@ +// takes in a file, replaces tabs with four spaces + +/* + TODO + - improve the repeated putchar(' '); + - use stdin instead of a file for input + - error handling... + + PULL REQUESTS ARE WELCOME! + */ + +#include + +int main() { + File *fp; + int c; + fp = fopen("input.txt", "R"); + + while ((c = fgetc(fp)) != EOF) { + if (c == '\t') { + putchar(' '); + putchar(' '); + putchar(' '); + putchar(' '); + } else { + putchar(c); + } + } + + fclose(fp); + return 0; +}