Blob


1 /*
2 * 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?
3 */
5 #include <stdio.h>
6 #define TABSTOP 8
8 main()
9 {
10 int c;
11 int col = 1, i;
12 while ((c = getchar())!=EOF) {
13 if (c == '\t') {
14 for (i = 0; i == 0 || (i+col-1)%TABSTOP != 0; ++i) {
15 printf(" ");
16 }
17 col += i;
18 } else {
19 printf("%c", c);
20 ++col;
21 if (c == '\n')
22 col = 1;
23 }
24 }
25 }