/*
 * K&R C Programming language
 * -----------------------------------------------------------
 * Exercise 1-20.
 *
 * Write a program *detab* that replaces tabs in the input with
 * the proper number of blanks to space to the next tab stop.
 * Assume a fixed set of tab stops, say every n columns.
 * Should n be a variable or a symbolic parameter?
 *
 */

#include <stdio.h>

#define NTAB 4

int
main(int argc, char *argv[])
{
    int c, i, col, nspace;

    col = 0;
    while ((c = getchar()) != EOF)
        if (c == '\t') {
            nspace = NTAB-col%NTAB;
            for (i = 0; i < nspace; ++i) {
                putchar(' ');
                ++col;
            }
        } else {
            putchar(c);
            col = c == '\n' ? 0 : col+1;
        }

    return 0;
}
