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