diff options
Diffstat (limited to 'reverse.c')
-rw-r--r-- | reverse.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -5,7 +5,7 @@ // Prototypes int get_line(char line[], int maxlength); void line_copy(char to[], char from[]); -void reverse_copy(char to[], char from[]); +void reverse_copy(char to[], char from[], int length); /* * MAIN @@ -17,7 +17,7 @@ int main() { char reversed_line[MAXLENGTH]; // current reversed line while ((len = get_line(line, MAXLENGTH)) > 0) { - reverse_copy(line, reversed_line, len); + reverse_copy(reversed_line, line, len); printf("%s\n", reversed_line); } return 0; @@ -61,8 +61,10 @@ void line_copy(char to[], char from[]) { void reverse_copy(char to[], char from[], int length) { int i; - i = 0; - while ((to[i] = from[i]) != '\0') - ++i; + for (i = 0; i < length; ++i) { + to[length - 1 - i] = from[i]; + } + + to[length] = '\0'; } |