diff options
author | sinanmohd <pcmsinan@gmail.com> | 2022-06-04 12:11:15 +0530 |
---|---|---|
committer | sinanmohd <pcmsinan@gmail.com> | 2022-06-04 12:11:15 +0530 |
commit | c24973af02bc33f2f5f25d37e22ca91da5de3c47 (patch) | |
tree | 460a005b6a3a9a967bd881bc2bf01e0becbe33cc /1.19.c |
inital commit
Diffstat (limited to '1.19.c')
-rw-r--r-- | 1.19.c | 70 |
1 files changed, 70 insertions, 0 deletions
@@ -0,0 +1,70 @@ +#include <stdio.h> + +#define MAXLINE 1000 + +void reverse(char str[]); +void str_cp(char to[], char from[]); + +int +main(void) +{ + int input, i; + char str[MAXLINE]; + + i = 0; + + while ((input = getchar()) != EOF) { + str[i] = input; + i++; + + if (input == '\n') { + str[i] = '\0'; + i = 0; + reverse(str); + printf("%s\n", str); + } + } + + return 0; +} + +void +str_cp(char to[], char from[]) +{ + int i, last_non_blank; + + last_non_blank = -1; + + for (i = 0; from[i] != '\0'; ++i) { + if (from[i] != ' '&& from[i] != '\n' && from[i] != '\t') + last_non_blank = i; + + to[i] = from[i]; + } + + if (last_non_blank >= 0) + to[last_non_blank+1] = '\0'; + else + to[i] = '\0'; +} + +void +reverse(char str[]) +{ + int i, len; + char storage[MAXLINE]; + + i = len = 0; + + str_cp (storage, str); + + for ( len = 0; storage[len] != '\0'; len++) + ; + + for ( i = 0; i < len; ++i) + str[i] = storage[len-1-i]; + + str[i] = '\0'; +} + + |