From 19fa3daff1447c633029e1730bf0355b21ee029f Mon Sep 17 00:00:00 2001 From: zlg Date: Mon, 26 Nov 2012 20:45:37 -0600 Subject: Solve Exercise 1-21: entab --- 1-20_detab.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to '1-20_detab.c') 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; } } } -- cgit v1.2.3-70-g09d2 h/diff/README.mdown?h=v0.3b8&id=e5abc98d05231cfb0c1a99248050773b23019860&follow=1'>diff
path: root/README.mdown (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2016-11-15Correct phrasing in README.Ze Libertine Gamer1-4/+4
2016-11-13DerpZe Libertine Gamer1-0/+1
2016-11-03Improve error handling in shell scriptsZe Libertine Gamer4-3/+23
2016-10-24Correct run_again, add recursionZe Libertine Gamer1-0/+4
2016-10-21Add quotes to correct behavior for arglistZe Libertine Gamer1-1/+1
2016-10-14updater.sh: add recursion, error handlingZe Libertine Gamer1-43/+101
2016-10-14Correct pipe-handling behaviorZe Libertine Gamer1-1/+9
2016-10-12Clarify a method to move between platformsZe Libertine Gamer1-2/+5