Skip to content

Commit 459953c

Browse files
Update Ex_1.12_word_per_line.c (#142)
this is another approach, simple and readab;e
1 parent fe761ad commit 459953c

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

languages/cprogs/Ex_1.12_word_per_line.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@
44
*
55
* */
66

7+
//suggesting a newer approach found on internet
8+
//concept is: do nothing if you meet more than 1 blankspaces or tab spaces or newlines or "anti word characters"
9+
#include<stdio.h>
10+
#define CTRL(x) (x & 0x1f)
11+
main()
12+
{
13+
int c;
14+
while((c = getchar()) != EOF && c != CTRL('d') )
15+
{
16+
if(c == ' ' || c == '\t' || c == '\n' || c == '-')
17+
{
18+
putchar('\n');
19+
while((c = getchar()) == ' ' || c == '\t' || c == '\n' || c == '-' )
20+
{
21+
; //do nothing // we could actually skip the braces and just enter ; after closing the while's condition brackets
22+
}
23+
}
24+
putchar(c);
25+
}
26+
}
27+
28+
29+
/*
730
#include <stdio.h>
831
#define IN 1
932
#define OUT 0
@@ -24,4 +47,5 @@ int main (int argc, char *argv[]) {
2447
else
2548
putchar(c);
2649
}
27-
}
50+
}
51+
*/

0 commit comments

Comments
 (0)