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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// I don't remember ever writing this. I think this is copied straight from K&R.
#include<stdio.h>
#include<stdlib.h>
#define MAXFILE 1000
#define MAXLINE 1000
int readline(char *line, int maxline);
int stripspace(char *line);
int main(int argc, char *argv[]) {
char line[MAXFILE][MAXLINE];
int inspace, outspace, i, linecount, space;
if (argc == 3) {
/* inspace = atoi(argv[1]);
outspace = atoi(argv[2]); */
inspace = 4;
outspace = 2;
i = linecount = 0;
while ( readline(line[i++], MAXLINE ) >= 0)
linecount++;
/* for (i = 0; i < linecount; i++) {
space = stripspace(line[i]);
space = space - space % inspace;
space = space / inspace * outspace;
addspace(line[i], space);
} */
} else {
return 1;
}
return 0;
}
int readline(char *string, int lim) {
int c, i;
i = 0;
while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
string[i++] = c;
if (c == '\n')
string[i++] = c;
if (c == EOF)
i = -1;
string[i] = '\0';
return i;
}
int stripspace(char *string) {
int i, ii;
i = ii = 0;
while (string[i] == ' ')
i++;
while ( (string[ii++] = string[i++]) != '\0')
;
return i - ii;
}
int addspace(char *string, int amount) {
int i, ii;
i = 0;
while ( string[i++] != '\0' )
;
ii = i + amount;
while (--i != -1) {
--ii;
string [ii] = string [i];
}
while (--ii != -1)
string [ii] = ' ';
}
|