Skip to content

Commit d37125c

Browse files
authored
Fix character assignment and null termination in loop
1 parent cafa649 commit d37125c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

chapter_2/exercise_2_02/loop.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@ int main(void)
1818
else if (c == EOF)
1919
break;
2020
else
21-
s[i] = c;
22-
23-
++i;
21+
s[i++] = c;
2422
}
23+
s[i] = '\0';
2524

26-
printf("\n%s\n", s);
25+
printf("%s\n", s);
2726

2827

2928
return 0;

0 commit comments

Comments
 (0)