mirror of
https://github.com/krislamo/knrc.git
synced 2024-11-10 00:30:35 +00:00
Exercise 1-18. Remove trailing blanks and tabs
This commit is contained in:
parent
42a0b5413b
commit
c6070adb67
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
int getline(char line[], int maxline);
|
int getline(char line[], int maxline);
|
||||||
void copy(char to[], char from[]);
|
void copy(char to[], char from[]);
|
||||||
|
void trim(char line[], int len);
|
||||||
|
|
||||||
/* print longest input line */
|
/* print longest input line */
|
||||||
main()
|
main()
|
||||||
@ -22,8 +23,10 @@ main()
|
|||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
++len;
|
++len;
|
||||||
}
|
}
|
||||||
if (len >= MINLINE)
|
if (len >= MINLINE) {
|
||||||
|
trim(line, len);
|
||||||
printf("%s", line);
|
printf("%s", line);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -52,3 +55,15 @@ void copy(char to[], char from[])
|
|||||||
while ((to[i] = from[i]) != '\0')
|
while ((to[i] = from[i]) != '\0')
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* trim: remove extraneous blanks and tabs */
|
||||||
|
void trim(char s[], int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = len-2; i >= 0; --i)
|
||||||
|
if (s[i] == ' ' || s[i] == '\t')
|
||||||
|
s[i] = '\0';
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user