Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Exercise 1-22. 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 MAX 1000
- char str[MAX];
- int fold(int len);
- int main()
- {
- int len;
- while ((len = fold(MAX)) > 0)
- printf("%s\n", str);
- return 0;
- }
- int fold(int len) {
- int c, i, lc;
- i = lc = 0;
- while ((c = getchar()) != EOF && c != '\n' && i < len - 1 ) {
- lc++;
- if (lc >= 40) {
- if (c != ' ' && c != '.' && c != ',' && c != ';' && c != '(')
- str[i++] = '-';
- str[i++] = '\n';
- lc = 0;
- }
- str[i++] = c;
- }
- str[i] = '\0';
- return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment