-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwenty2.c
66 lines (56 loc) · 888 Bytes
/
twenty2.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include<stdio.h>
#define MAXCOLM 10
#define TABINC 8
char line[MAXCOLM];
int findblk(int pos);
void printl(int pos);
int newpos(int pos);
//int exptab(int pos);
main()
{
int pos,c;
pos = 0;
while ((c == getchar()) != EOF ) {
line[pos] = c;
if (c == '\n') {
printl(pos);
pos = 0;
} else if (++pos >= MAXCOLM) {
pos = findblk(pos);
printl(pos);
pos = newpos(pos);
} else if (c == '\t') {
//pos = exptab(pos);
}
}
}
void printl(int pos)
{
int i;
for (i=0; i<pos; ++i)
putchar(line[i]);
if (pos > 0)
putchar('\n');
}
int findblk(int pos)
{
while (pos > 0 && line[pos] != ' ')
--pos;
if (pos == 0)
return MAXCOLM;
else
return pos+1;
}
int newpos(int pos) {
int i,j;
if (pos <= 0 || pos >= MAXCOLM)
return 0;
else {
i = 0;
for (j = pos; j < MAXCOLM; ++j) {
line[i] = line[j];
++i;
}
return i;
}
}