-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx120.c
33 lines (29 loc) · 776 Bytes
/
x120.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* 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 n 4
main()
{
int c,i = 0;
while ((c=getchar())!=EOF)
{
if (c == '\t')
{
/* every tab must be replaced by at least one space */
putchar(0x20);
/* additional spaces put until tab stop is reached */
while(++i%n) putchar(0x20);
}
else
{
/* normal char piping */
putchar(c);
i++;
}
if (c == '\n') i=0;
}
}
/* This line starts with 3 tabs */