diff --git a/1-20.c b/1-20.c new file mode 100644 index 0000000..226b35c --- /dev/null +++ b/1-20.c @@ -0,0 +1,46 @@ +#include +/* program detab + replaces tab in the input with the + proper number of blank spaces to + the next tab stop + + assume a fixed set of tab stops, + say, every n columns */ + +#define MAXLINE 1000 +#define COLPERTAB 8 + +int ggetline(char line[], int maxline){ + int character, index; + for(index = 0; index < maxline - 1 + && (character = getchar()) != EOF + && character != '\n'; index++){ + line[index] = character; + } + line[index] = '\0'; + return index; +} + +int main(){ + char line[MAXLINE]; + int index, length, column, index2; + while ((length = ggetline(line, MAXLINE)) > 0){ + column = index = 0; + while(index < length){ + if (line[index] != '\t'){ + putchar(line[index]); + column++; + } + if (line[index] == '\t'){ + index2 = COLPERTAB - (column % COLPERTAB); + column += index2; + for(; index2 > 0; index2--){ + putchar(' '); + } + } + index++; + } + putchar('\n'); + } + return 0; +}