8
8
*/
9
9
10
10
/*
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 .
14
14
*/
15
15
16
16
#include <stdio.h>
17
17
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 */
20
20
21
21
/* functions */
22
22
int getLine (char [], int );
@@ -37,30 +37,30 @@ int getLine(char s[], int lim)
37
37
}
38
38
39
39
/* detab function: replaces tabs with the proper number of blanks */
40
- void detab (char line [], char modLine [])
40
+ void detab (char in [], char out [])
41
41
{
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 */
45
45
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 ++ ] = ' ' ;
51
51
} else
52
- modLine [j ++ ] = line [i ];
53
- modLine [j ] = '\0' ;
52
+ out [j ++ ] = in [i ];
53
+ out [j ] = '\0' ;
54
54
}
55
55
56
56
int main (void )
57
57
{
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 */
60
60
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 );
64
64
}
65
65
return 0 ;
66
66
}
0 commit comments