1 5dc21454 2023-07-14 jrmu /* 1-18. Write a program to remove trailing blanks and tabs from each
2 5dc21454 2023-07-14 jrmu * line of input, and to delete entirely blank lines.
5 5dc21454 2023-07-14 jrmu /* MAXLINE has been reduced for easier testing */
6 5dc21454 2023-07-14 jrmu #include <stdio.h>
7 5dc21454 2023-07-14 jrmu #define MAXLINE 1000
9 5dc21454 2023-07-14 jrmu int getlin(char line[], int maxline);
10 5dc21454 2023-07-14 jrmu void copy(char to[], char from[]);
14 5dc21454 2023-07-14 jrmu int len; /* current line length */
15 5dc21454 2023-07-14 jrmu char line[MAXLINE]; /* current input line */
17 5dc21454 2023-07-14 jrmu while ((len = getlin(line, MAXLINE)) > 0) {
18 5dc21454 2023-07-14 jrmu if (line[0] != '\0')
19 5dc21454 2023-07-14 jrmu printf("%s\n", line);
24 5dc21454 2023-07-14 jrmu int getlin(char s[], int lim)
26 5dc21454 2023-07-14 jrmu int c, i, nullchar;
27 5dc21454 2023-07-14 jrmu nullchar = 0;
29 5dc21454 2023-07-14 jrmu for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i) {
30 5dc21454 2023-07-14 jrmu if (c != '\t' && c != ' ') {
31 5dc21454 2023-07-14 jrmu nullchar = i+1;
35 5dc21454 2023-07-14 jrmu if (c == '\n')
37 5dc21454 2023-07-14 jrmu s[nullchar] = '\0';
41 5dc21454 2023-07-14 jrmu void copy(char to[], char from[])
45 5dc21454 2023-07-14 jrmu while ((to[i] = from[i]) != '\0')