mirror of
https://github.com/krislamo/knrc.git
synced 2024-11-10 00:30:35 +00:00
Compare commits
3 Commits
9fd4d3db68
...
c6070adb67
Author | SHA1 | Date | |
---|---|---|---|
c6070adb67 | |||
42a0b5413b | |||
f254c6e67e |
@ -1,25 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#define MAXLINE 1000 /* maximum input line size */
|
||||
#define MINLINE 81
|
||||
|
||||
int getline(char line[], int maxline);
|
||||
void copy(char to[], char from[]);
|
||||
void trim(char line[], int len);
|
||||
|
||||
/* print longest input line */
|
||||
main()
|
||||
{
|
||||
int len;
|
||||
int max;
|
||||
int c;
|
||||
char line[MAXLINE];
|
||||
char longest[MAXLINE];
|
||||
|
||||
max = 0;
|
||||
while((len = getline(line, MAXLINE)) > 0)
|
||||
if (len > max) {
|
||||
max = len;
|
||||
copy(longest, line);
|
||||
while((len = getline(line, MAXLINE)) > 0) {
|
||||
if (line[len-1] != '\n') {
|
||||
while ((c=getchar())!=EOF && c!='\n')
|
||||
++len;
|
||||
if (c == '\n')
|
||||
++len;
|
||||
}
|
||||
if (len >= MINLINE) {
|
||||
trim(line, len);
|
||||
printf("%s", line);
|
||||
}
|
||||
}
|
||||
if (max > 0)
|
||||
printf("%s", longest);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -47,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