/*
* 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.
*
* fduan, Dec. 12, 2011
*/
#include <stdio.h>
#define MAX_COL 10
int main()
{
int c, i;
char line[MAX_COL + 1] = { '\0' };
i = 0;
while( ( c = getchar() ) != EOF )
{
line[i++] = c;
if( i == MAX_COL )
{
line[i--] = '\0';
while( line[i] == ' ' || line[i] == '\t' )
--i;
line[i+1] = '\0';
printf( "%s\n", line );
i = 0;
}
}
return 0;
}K&R C Exercise 1-22 Solution
最新推荐文章于 2019-07-24 22:34:17 发布
本文介绍了一个使用C语言编写的程序,该程序可以将长输入行根据指定的列数进行折叠,确保每行不超过预定义的最大列数。当达到最大列数时,程序会查找最后一个非空白字符并在此处换行。

475

被折叠的 条评论
为什么被折叠?



