-
Notifications
You must be signed in to change notification settings - Fork 3
/
1-22.c
42 lines (41 loc) · 1.25 KB
/
1-22.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <ctype.h>
#define LAST_COLUMN_OF_INPUT 5
int main ()
{
char line[LAST_COLUMN_OF_INPUT];
char character;
int charOnTheLine = 0, blanksBeforeFold = 0;
while ((character = getchar()) != EOF) {
if (charOnTheLine < LAST_COLUMN_OF_INPUT) {
line[charOnTheLine] = character;
charOnTheLine++;
}
if (character == '\n') {
for (int index = 0; index < charOnTheLine; index++) {
putchar(line[index]);
}
blanksBeforeFold = 0;
charOnTheLine = 0;
putchar('\n');
}
if (charOnTheLine == LAST_COLUMN_OF_INPUT) {
while (isspace(line[charOnTheLine-1])) {
blanksBeforeFold++;
charOnTheLine--;
}
for (charOnTheLine = 0; charOnTheLine < (LAST_COLUMN_OF_INPUT - blanksBeforeFold); charOnTheLine ++) {
putchar(line[charOnTheLine]);
}
blanksBeforeFold = 0;
charOnTheLine = 0;
putchar('\n');
}
}
if ((character = getchar()) == EOF) {
for (int index = 0; index < charOnTheLine; index++) {
putchar(line[index]);
}
}
return 0;
}