Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 TABSSTOP 8
- int
- main() {
- int c;
- int offset = 0;
- int spaces;
- while ((c = getchar()) != EOF) {
- if (c == '\t') {
- spaces = TABSSTOP - (offset%TABSSTOP);
- offset += spaces;
- while (spaces--)
- putchar(' ');
- } else {
- if (c == '\n')
- offset = -1;
- offset++;
- putchar(c);
- }
- }
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment