Skip to content

Commit 767ce08

Browse files
committed
rename variables
1 parent 761ef74 commit 767ce08

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

chapter01/1-20.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
*/
99

1010
/*
11-
* Answer: n should be a symbolic parameter, for the value of n should remain
12-
* constant throughout the duration of the program. A change in n would break
13-
* the algorithm.
11+
* Answer: Here, n should be a symbolic constant, for the value of n
12+
* should remain constant throughout the duration of the program. It could also
13+
* be a const int.
1414
*/
1515

1616
#include <stdio.h>
1717

18-
#define MAXLINE 1000
19-
#define N 4 /* tabstop for every n columns */
18+
#define MAXLEN 1000
19+
#define N 4 /* tabstop for every n columns */
2020

2121
/* functions */
2222
int getLine(char [], int);
@@ -37,30 +37,30 @@ int getLine(char s[], int lim)
3737
}
3838

3939
/* detab function: replaces tabs with the proper number of blanks */
40-
void detab(char line[], char modLine[])
40+
void detab(char in[], char out[])
4141
{
42-
int i; /* index for read line */
43-
int j; /* index for modified (written) line */
44-
int blanksToTabStop; /* number of blanks to the next tab stop */
42+
int i; /* index for read line */
43+
int j; /* index for modified (written) line */
44+
int nblanks; /* number of blanks to the next tab stop */
4545

46-
for (i = j = 0; line[i] != '\0'; ++i)
47-
if (line[i] == '\t') {
48-
blanksToTabStop = N - (j % N);
49-
while (blanksToTabStop-- > 0)
50-
modLine[j++] = ' ';
46+
for (i = j = 0; in[i] != '\0'; ++i)
47+
if (in[i] == '\t') {
48+
nblanks = N - (j % N);
49+
while (nblanks-- > 0)
50+
out[j++] = ' ';
5151
} else
52-
modLine[j++] = line[i];
53-
modLine[j] = '\0';
52+
out[j++] = in[i];
53+
out[j] = '\0';
5454
}
5555

5656
int main(void)
5757
{
58-
char line[MAXLINE]; /* currently read line */
59-
char modLine[MAXLINE]; /* modified line */
58+
char in[MAXLEN]; /* currently read line */
59+
char out[MAXLEN]; /* modified line */
6060

61-
while (getLine(line, MAXLINE) > 0) {
62-
detab(line, modLine);
63-
printf("%s", modLine);
61+
while (getLine(in, MAXLEN) > 0) {
62+
detab(in, out);
63+
printf("%s", out);
6464
}
6565
return 0;
6666
}

0 commit comments

Comments
 (0)