mirror of
https://github.com/krislamo/knrc.git
synced 2024-11-10 00:30:35 +00:00
Exercise 1-19. Write a function reverse(s)
This commit is contained in:
parent
c6070adb67
commit
da9de48bac
@ -1,10 +1,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define MAXLINE 1000 /* maximum input line size */
|
#define MAXLINE 1000 /* maximum input line size */
|
||||||
#define MINLINE 81
|
#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 trim(char line[], int len);
|
||||||
|
void reverse(char to[], char from[], int len);
|
||||||
|
|
||||||
/* print longest input line */
|
/* print longest input line */
|
||||||
main()
|
main()
|
||||||
@ -13,7 +14,7 @@ main()
|
|||||||
int max;
|
int max;
|
||||||
int c;
|
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) {
|
||||||
@ -24,8 +25,8 @@ main()
|
|||||||
++len;
|
++len;
|
||||||
}
|
}
|
||||||
if (len >= MINLINE) {
|
if (len >= MINLINE) {
|
||||||
trim(line, len);
|
reverse(enil, line, len);
|
||||||
printf("%s", line);
|
printf("%s", enil);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -67,3 +68,14 @@ void trim(char s[], int len)
|
|||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void reverse(char to[], char from[], int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while ((to[i] = from[len-1]) != '\0') {
|
||||||
|
++i;
|
||||||
|
--len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user