diff options
author | sinanmohd <sinan@firemail.cc> | 2023-05-11 16:09:33 +0530 |
---|---|---|
committer | sinanmohd <sinan@firemail.cc> | 2023-05-11 21:09:58 +0530 |
commit | f481f43596073d7f5cee231da901fb43d6af8366 (patch) | |
tree | 80460b62acf783b39793fe0c66943e0ee23f33bb /7.2/main.c | |
parent | c2e62961609da793219749028e0477adc980451a (diff) |
7.2: initial commit
Diffstat (limited to '7.2/main.c')
-rw-r--r-- | 7.2/main.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/7.2/main.c b/7.2/main.c new file mode 100644 index 0000000..f11256e --- /dev/null +++ b/7.2/main.c @@ -0,0 +1,50 @@ +#include <stdio.h> +#include <ctype.h> +#include "getch.h" + +#define MAXLINE 80 +#define OCTLEN 6 + +int inc(int col, int n); + +int main(void) +{ + char c, col, next; + + col = 0; + while ((c = getch()) != EOF) { + if (iscntrl(c) || isblank(c)) { + col = inc(col, OCTLEN); + printf(" \\%03o ", c); + + if (c == '\n') { + col = 0; + putchar(c); + } + } else { + col = inc(col, 1); + /* ac- + * k */ + ungetch(next = getch()); + if (col == MAXLINE && isalpha(c) && + isalpha(next)) { + ungetch(c); + c = '-'; + } + + putchar(c); + } + } + + return 0; +} + +int inc(int col, int n) +{ + if (col + n > MAXLINE) { + putchar('\n'); + return n; + } else { + return col + n; + } +} |