mirror of
https://github.com/krislamo/knrc.git
synced 2025-01-05 19:10:36 +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>
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user