Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/cprogs/Ex_1.20_detab.c
1240 views
1
/**
2
* Exercise 1.20 -
3
*
4
* Write a Program detab, which replaces tabs in the input with a proper
5
* number of blanks to spaces
6
*
7
**/
8
9
10
#include<stdio.h>
11
12
#define TABINC 8
13
14
int main(void)
15
{
16
int nb,pos,c;
17
18
nb = 0;
19
pos = 1;
20
21
while((c=getchar())!=EOF)
22
{
23
if( c == '\t')
24
{
25
nb = TABINC - (( pos - 1) % TABINC);
26
27
while( nb > 0)
28
{
29
putchar('#');
30
++pos;
31
--nb;
32
}
33
}
34
else if( c == '\n')
35
{
36
putchar(c);
37
pos = 1;
38
}
39
else
40
{
41
putchar(c);
42
++pos;
43
}
44
}
45
46
return 0;
47
}
48
49