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);
|
||||
void copy(char to[], char from[]);
|
||||
void trim(char line[], int len);
|
||||
|
||||
/* print longest input line */
|
||||
main()
|
||||
@ -22,9 +23,11 @@ main()
|
||||
if (c == '\n')
|
||||
++len;
|
||||
}
|
||||
if (len >= MINLINE)
|
||||
if (len >= MINLINE) {
|
||||
trim(line, len);
|
||||
printf("%s", line);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -52,3 +55,15 @@ void copy(char to[], char from[])
|
||||
while ((to[i] = from[i]) != '\0')
|
||||
++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