Skip to content

Commit dfb993f

Browse files
authored
Update reverse.c
1 parent 77b2330 commit dfb993f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

chapter_1/exercise_1_19/reverse.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int get_line(char line[], int max_line_len)
3131
++i;
3232
}
3333

34-
// flush out input stream if exceeding MAXLINE limit
34+
// flush out input stream if exceeding max_line_len limit
3535
while (i >= max_line_len - 1 && (c = getchar()) != '\n')
3636
;
3737

@@ -62,7 +62,15 @@ void reverse(char line[])
6262
int i_back = length(line);
6363
char temp;
6464

65-
i_back = line[i_back - 1] == '\n'? i_back - 2: i_back - 1;
65+
if(line[i_back - 1] == '\n')
66+
{
67+
i_back -= 2;
68+
}
69+
else
70+
{
71+
i_back -= 1;
72+
}
73+
6674
while (i_back > i_front)
6775
{
6876
temp = line[i_front];

0 commit comments

Comments
 (0)