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

Exercise 1-19. Write a function reverse(s)

This commit is contained in:
Kris Lamoureux 2021-12-02 20:29:00 -05:00
parent c6070adb67
commit da9de48bac
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925

View File

@ -1,10 +1,11 @@
#include <stdio.h>
#define MAXLINE 1000 /* maximum input line size */
#define MINLINE 81
#define MINLINE 0
int getline(char line[], int maxline);
void copy(char to[], char from[]);
void trim(char line[], int len);
void reverse(char to[], char from[], int len);
/* print longest input line */
main()
@ -13,7 +14,7 @@ main()
int max;
int c;
char line[MAXLINE];
char longest[MAXLINE];
char enil[MAXLINE];
max = 0;
while((len = getline(line, MAXLINE)) > 0) {
@ -24,8 +25,8 @@ main()
++len;
}
if (len >= MINLINE) {
trim(line, len);
printf("%s", line);
reverse(enil, line, len);
printf("%s", enil);
}
}
return 0;
@ -67,3 +68,14 @@ void trim(char s[], int len)
else
return;
}
void reverse(char to[], char from[], int len)
{
int i;
i = 0;
while ((to[i] = from[len-1]) != '\0') {
++i;
--len;
}
}