forked from wuqingze/cprogramminglanguage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
34.entab.c
52 lines (43 loc) · 764 Bytes
/
34.entab.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
#include <stdio.h>
#define MAXLINE 1000
int myGetline(char line[], int maxline);
main(int argc, char *argv[])
{
int c, len;
int i;
char line[MAXLINE];
int tabstop;
int spaceCount;
if (argc == 1)
tabstop = 8;
else if (argc == 2)
tabstop = atoi(*++argv);
else {
printf("Usage entab (8)(tabstop)\n");
return 1;
}
while ((len = myGetline(line, MAXLINE)) > 0) {
spaceCount = 0;
for (i = 0; i < len; ++i) {
if (line[i] == ' ')
spaceCount++;
else
spaceCount = 0;
if (spaceCount == tabstop) {
}
}
printf("%s", line);
}
}
int myGetline(char s[], int lim)
{
int c, i;
for (i = 0; i < lim - 1 && (c = getchar()) != EOF && c != '\n'; ++i)
s[i] = c;
if (c == '\n') {
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}