1
0
mirror of https://github.com/krislamo/knrc.git synced 2024-09-19 21:00:35 +00:00

Exercise 1-18. Remove trailing blanks and tabs

This commit is contained in:
Kris Lamoureux 2021-11-30 01:43:24 -05:00
parent 42a0b5413b
commit c6070adb67
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925

View File

@ -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,8 +23,10 @@ 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;
}