-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1-19.c
More file actions
39 lines (34 loc) · 709 Bytes
/
Copy path1-19.c
File metadata and controls
39 lines (34 loc) · 709 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#define MAXLINE 8000
int agetline(char s[], int lim);
void reverse(char to[], char from[], int len);
int main()
{
int len;
char line[MAXLINE];
char longest[MAXLINE];
while ((len = agetline(line, MAXLINE)) > 0) {
reverse(longest, line, len-1);
printf("%s", longest);
}
return 0;
}
int agetline(char s[], int lim) /*no need to correctly manage \n and \0 */
{
int c, i;
for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
s[i] = c;
return i;
}
void reverse(char to[], char from[], int len) /*mangaging is done here instead*/
{
int i;
i = 0;
while (len >= 0) {
to[i] = from[len];
++i;
--len;
}
to[i] = '\n';
to[++i] = '\0';
}