commit - 5a3cc2ca160febcfc5fc81eb508016154cce2510
commit + 64af102f736c4ef596d82f1a48e3536927ce32b0
blob - a07c8fabfb78cd087ef005abf009b4772cec9236
blob + e9b378a2dd0b8cbeff0753c414845268108a3fba
--- 1-20.c
+++ 1-20.c
* number of blanks to space to the next tab stop. Assume a fixed set of tab
* stops, say every n columns. Should n be a variable or a symbolic parameter?
* */
-
-#include <stdio.h>
-
-#define MAXLINE 1000 /* maximum input line size */
-
-int getlin(char line[], int maxline);
-void reverse(char s[]);
-int length(char s[]);
-
-int main() {
- int len; /* current line length */
- char line[MAXLINE]; /* current input line */
-
- while ((len = getlin(line, MAXLINE)) > 0) {
- reverse(line);
- printf("%s", line);
- }
- return 0;
-}
-
-/* getlin: read a line into s, return length */
-int getlin(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;
-}
-
-/* length: returns the length of character string s */
-int length(char s[]) {
- int i = 0;
- while (s[i] != '\0')
- i++;
- return i;
-}
-
-/* reverse: reverses the character string s */
-void reverse(char s[]) {
- char temp;
- int i = 0;
- int j = length(s) - 1;
- /* don't reverse newline */
- if (s[j] == '\n')
- j--;
- for (; i < j; i++, j--) {
- temp = s[i];
- s[i] = s[j];
- s[j] = temp;
- }
-}