1-22编写一个程序,把较长的输入行“折”成短一些的两行或多行,折行的位置在输入行的第n列之前的最后一个非空格之后。 要保证程序能够智能地处理输入行很长以及在制定的列前没有空格或制表符时的情况

#include<stdio.h>
#define TABINC 3
int main() {
int c,i;
c=0; //i为输入字符的位数
for (i = 1; (c = getchar()) != EOF;i++) {
if (c == '\n') {
printf("\n");
i = 0;
}
if (c == '\t') {
printf("\t");
i = 0;
}
if (i % TABINC != 0){
putchar(c);
}
else {
putchar(c);
printf("\n");
i = 0;
}
}
}

posted @ 2022-03-15 10:46  笨笨的小虫子  阅读(57)  评论(0)    收藏  举报