Exercise 1-20. Write a program detab that replaces tabs in the input with the proper numberof 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 TABWIDTH 8
int main(){ char s[200], c; int len, t;
len = 0; while((c = getchar()) != '\n'){ if(c != '\t') s[len++] = c; else for(t = TABWIDTH - len % TABWIDTH; t > 0; t--) s[len++] = ' '; } s[len++] = c; s[len] = '\0'; printf("%s", s); }
|
阅读(524) | 评论(0) | 转发(0) |