Skip to content

Commit

Permalink
Merge pull request #59 from caldotdev/main
Browse files Browse the repository at this point in the history
fix exercise 1-12 edge cases
  • Loading branch information
ohkimur authored Jan 9, 2024
2 parents 1506a2a + 80acbba commit 933e245
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions chapter_1/exercise_1_12/copy_io_nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@

int main()
{
char c;
char last_char = -1;
int character;
int previous_character = EOF;

while ((c = getchar()) != EOF) {
if((c==' ' || c=='\t' || c=='\n')) {
if(c != last_char) {
while ((character = getchar()) != EOF) {
if (character == ' ' || character == '\t' || character == '\n') {
if (previous_character != ' ' && previous_character != '\t' && previous_character != '\n') {
putchar('\n');
}
}
else {
putchar(c);
putchar(character);
}

last_char=c;
previous_character = character;
}

return 0;
}

0 comments on commit 933e245

Please sign in to comment.