diff options
Diffstat (limited to '1-20_detab.c')
-rw-r--r-- | 1-20_detab.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/1-20_detab.c b/1-20_detab.c index 3101610..e1549e6 100644 --- a/1-20_detab.c +++ b/1-20_detab.c @@ -5,11 +5,15 @@ * "Write a program `detab` that replaces tabs in the input with the proper * number of blanks to space to the next tabstop. Assume a fixed set of * tabstops, say every 'n' columns. Should 'n' be a variable or a symbolic - * parameter? + * parameter?" * * Answer: 'n' should be a symbolic parameter. It's more apparent what's being * worked with and it's not susceptible to scope. Though, in this simple * program it really doesn't matter. + * + * To be correct, this file should use the isprint() function to ensure that + * 'column' only gets incremented when a printable character is being read. I'll + * come back to this when I learn more of the stdlib. */ #define TABWIDTH 8 @@ -30,12 +34,14 @@ int main(void) { ++column; } } else { - // non-tabs simply get output. - putchar(c); - ++column; - // Line-endings should reset the column counter after being output. if (c == '\n') { + // Line-endings should reset the column counter after being output. + putchar(c); column = 0; + } else { + // Now we can just output and increase column! + putchar(c); + ++column; } } } |