mirror of
https://github.com/krislamo/knrc.git
synced 2025-09-17 10:29:30 +00:00
Compare commits
4 Commits
9fd4d3db68
...
main
Author | SHA1 | Date | |
---|---|---|---|
da9de48bac
|
|||
c6070adb67
|
|||
42a0b5413b
|
|||
f254c6e67e
|
@@ -1,25 +1,34 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define MAXLINE 1000 /* maximum input line size */
|
#define MAXLINE 1000 /* maximum input line size */
|
||||||
|
#define MINLINE 0
|
||||||
|
|
||||||
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);
|
||||||
|
void reverse(char to[], char from[], 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 enil[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);
|
reverse(enil, line, len);
|
||||||
|
printf("%s", enil);
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,3 +56,26 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reverse(char to[], char from[], int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while ((to[i] = from[len-1]) != '\0') {
|
||||||
|
++i;
|
||||||
|
--len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user