We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5fd36ec commit 77b2330Copy full SHA for 77b2330
chapter_1/exercise_1_19/reverse.c
@@ -31,6 +31,10 @@ int get_line(char line[], int max_line_len)
31
++i;
32
}
33
34
+ // flush out input stream if exceeding MAXLINE limit
35
+ while (i >= max_line_len - 1 && (c = getchar()) != '\n')
36
+ ;
37
+
38
if (c == '\n')
39
{
40
line[i] = '\n';
@@ -58,7 +62,7 @@ void reverse(char line[])
58
62
int i_back = length(line);
59
63
char temp;
60
64
61
- i_back -= 2;
65
+ i_back = line[i_back - 1] == '\n'? i_back - 2: i_back - 1;
66
while (i_back > i_front)
67
68
temp = line[i_front];
0 commit comments