Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************************************************************
- * *
- * Write a program to "fold" long input lines into two or more shorter lines after the last non-blank character *
- * that occurs before the n-th column of input. Make sure your program does something intelligent with very long *
- * lines, and if there are no blanks or tabs before the specified column. *
- * *
- *****************************************************************************************************************/
- #include <stdio.h>
- #define LONGLINE 80 /* 80+ znakov je dlhy riadok, softlimit */
- #define MAXLINE 800 /* 800+ znakov je prilis dlhy riadok, hardlimit */
- int main(void) {
- int c, i; /* miesto pre nacitany znak a pocet znakov v riadku */
- i = 0; /* na zaciatku sme na nultej pozicii riadku */
- while ((c = getchar()) != EOF) { /* nacitavame znaky az do EOF */
- if (i >= LONGLINE) /* sme za softlimit dlzky riadku? */
- if (c == '\t' || c == ' ') /* ano sme, tak ak pride medzera alebo TAB, nahradime ich '\n' */
- c = '\n';
- else if (i >= MAXLINE) { /* sme za hardlimit riadku? */
- putchar('\n'); /* ano sme, tak natvrdo zaradime '\n' */
- i = 0; /* nastavime poziciu na riadku na nulu */
- }
- putchar(c); /* vytlacime bud povodny znak, alebo nahradeny '\n' za '\t' alebo ' ' po dosiahnuti softlimitu */
- if (c != '\n') /* posunieme sa v riadku iba vtedy, ak nie sme '\n' */
- ++i;
- else /* sme '\n', tak vynulujeme poziciu na riadku */
- i = 0;
- }
- return 0; /* slusne sa rozlucime */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement