简单的自动换行问题不包装 [英] simple word wrap problem not wrapping

查看:38
本文介绍了简单的自动换行问题不包装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过关于这个问题的各种想法,但是我没有看到自动换行。


你能指出什么是错的吗?这是一个K& R练习,我仍然是编程的b / b
。其他指针也会有所帮助。


#include" header.h"

/ *做文字包装* /


void fold(char buffer [],int len)

{

int start_point,i;


start_point = i = 0;

while(len>(start_point + COLUMN)){

i = start_point + COLUMN;

while(buffer [ i]!=''''|| buffer [i]!=''\ t'')

start_point = - i;

buffer [++ i] =''\ n'';

}

start_point = i = 0;


返回;

}


[来自header.h的片段]


/ * header.h * /

#include< stdio.h>

#define MAXLINE 1000 / *最大输入行大小* /

#define COLUMN 35 / *折叠前的长度* /

I''ve tried various ideas on this problem, but I don''t see word wrapping.

Can you point out what is wrong? It''s a K&R exercise, and I''m still new to
programming. Other pointers would be helpful too.

#include "header.h"
/* does the wordwrapping */

void fold(char buffer[], int len)
{
int start_point,i;

start_point=i=0;
while (len > (start_point +COLUMN)) {
i=start_point+COLUMN;
while ( buffer[i]!='' '' || buffer[i]!=''\t'')
start_point=--i;
buffer[++i]=''\n'';
}
start_point=i=0;

return;
}

[snippet from header.h]

/* header.h */
#include <stdio.h>
#define MAXLINE 1000 /* maximum input line size */
#define COLUMN 35 /* length before fold */

推荐答案



" Douglas G" < DG ******* @ houston.rr.com>写了

"Douglas G" <dg*******@houston.rr.com> wrote

我已经尝试过关于这个问题的各种想法,但是我没有看到包装文字。

你能指出什么是错的吗?这是一个K& R练习,我仍然是编程的新b
。其他指针也会有所帮助。

#include" header.h"
/ * wordwrapping * /

这个评论比注意要好,但是还是太简洁了。描述函数的意图

。它是否采用任意长度的字符串

并用换行符替换空格来实现包装?如果是这样,如果

传递了一个简并的不可绕行字符串,该怎么办?

为什么要传递字符串的长度?这是否意味着字符串需要

不是NUL终止的,还是效率?你需要解释一下。
void fold(char buffer [],int len)
{} int start_point,i;

start_point = i = 0;

while(len>(start_point + COLUMN)){
i = start_point + COLUMN;
while(buffer [i]!=''''|| buffer [i] !=''\ t'')
start_point = - i;
缓冲区[++ i] =''\ n'';
}
start_point = i = 0;

逻辑看起来非常狡猾。记住你可以传递任何字符串。

返回;
}
[来自header.h的片段]

/ *标题。 h * /
#include< stdio.h>
#define MAXLINE 1000 / *最大输入线尺寸* /
#define COLUMN 35 / *折叠前的长度* /

I''ve tried various ideas on this problem, but I don''t see word wrapping.

Can you point out what is wrong? It''s a K&R exercise, and I''m still new to programming. Other pointers would be helpful too.

#include "header.h"
/* does the wordwrapping */
This comment is better than noting, but still way too terse. Describe what
the function is meant to do. Does it take in a string of arbitrary length
and replace spaces by newlines to achieve wrapping? If so what does it do if
passed a degenerate unwrappable string?
Why are you passing the length of the string? Does this mean the string need
not be NUL-terminated, or is it for efficiency? You need to explain.
void fold(char buffer[], int len)
{
int start_point,i;

start_point=i=0;

while (len > (start_point +COLUMN)) {
i=start_point+COLUMN;
while ( buffer[i]!='' '' || buffer[i]!=''\t'')
start_point=--i;
buffer[++i]=''\n'';
}
start_point=i=0;
The logic looks highly dodgy to me. Remember you can be passed any string.

return;
}

[snippet from header.h]

/* header.h */
#include <stdio.h>
#define MAXLINE 1000 /* maximum input line size */
#define COLUMN 35 /* length before fold */



Malcolm写道:
Malcolm wrote:

Douglas G < DG ******* @ houston.rr.com>写了

"Douglas G" <dg*******@houston.rr.com> wrote

我已经尝试过关于这个问题的各种想法,但是我没有看到包装文字。

你能指出什么是错的吗?这是一个K& R练习,我还是新的

I''ve tried various ideas on this problem, but I don''t see word wrapping.

Can you point out what is wrong? It''s a K&R exercise, and I''m still new


编程。其他指针也会有所帮助。

#include" header.h"
/ *做wordwrapping * /
programming. Other pointers would be helpful too.

#include "header.h"
/* does the wordwrapping */


这个评论比注意要好,但是还是太简洁了。描述函数的意图。它是否采用任意长度的字符串
并用换行符替换空格来实现包装?如果是这样的话,如果传递了一个退化的不可绕行的字符串,那该怎么办?
为什么要传递字符串的长度?这是否意味着字符串
不需要NUL终止,或者它是否有效率?你需要解释一下。


This comment is better than noting, but still way too terse. Describe what
the function is meant to do. Does it take in a string of arbitrary length
and replace spaces by newlines to achieve wrapping? If so what does it do
if passed a degenerate unwrappable string?
Why are you passing the length of the string? Does this mean the string
need not be NUL-terminated, or is it for efficiency? You need to explain.




基本的自动换行,在某个列长度它检查是否有

空格并用它替换它换行符。否则它会重新计入第一个空白区域并重新点亮它。然后计数器应设置为

下一个位置。因此,如果该线实际上长于几列

长度,它将会捕获。


部分练习。捕获输入的例程在末尾放置一个null

终止符,并将长度传回。节省我的时间

试图再次查找长度。



Basic word wrap in that at a certain column length it checks if there is
white space and replaces it with a newline. Otherwise it counts back to
the first white space and repplaces it. Then the counter should be set to
the next spot. So if the line is actually longer than several column
lengths it will catch.

Part of the exercise. The routine that catches the input places a null
terminator at the end as well as passes the length back. Saves me time
trying to find the length again.


void fold(char buffer [],int len)
{zh_cn int start_point,i;

start_point = i = 0;

while(len>(start_point + COLUMN)){
i = start_point + COLUMN;
while(buffer [i]!=''''|| buffer [i]!=''\t'')
start_point = - i;
buffer [++ i] =''\ n'';
}
start_point = i = 0;

void fold(char buffer[], int len)
{
int start_point,i;

start_point=i=0;

while (len > (start_point +COLUMN)) {
i=start_point+COLUMN;
while ( buffer[i]!='' '' || buffer[i]!=''\t'')
start_point=--i;
buffer[++i]=''\n'';
}
start_point=i=0;


逻辑对我来说非常狡猾。记住你可以通过任何
字符串。


The logic looks highly dodgy to me. Remember you can be passed any
string.



有什么建议吗?我是编程新手。我觉得它很简洁

够了。它仍未通过最终测试,即它是否有效?返回;


[来自header.h的片段]

/ * header.h * /
#include< stdio.h>
#define MAXLINE 1000 / *最大输入线尺寸* /
#define COLUMN 35 / *折叠前的长度* /

Any suggestions on it? I''m new to programming. I thought it was concise
enough. It still fails the final test, which is, "does it work?" return;
}

[snippet from header.h]

/* header.h */
#include <stdio.h>
#define MAXLINE 1000 /* maximum input line size */
#define COLUMN 35 /* length before fold */








2004年8月31日星期二,Malcolm写道:

On Tue, 31 Aug 2004, Malcolm wrote:

Douglas G < DG ******* @ houston.rr.com>写了

"Douglas G" <dg*******@houston.rr.com> wrote
我已经尝试过关于这个问题的各种想法,但是我没有看到自动换行。
你能指出什么是错的吗?
[...] / *执行wordwrapping * /
I''ve tried various ideas on this problem, but I don''t see word wrapping.
Can you point out what is wrong? [...] /* does the wordwrapping */


这个评论比不是[h]更好,但仍然太简洁了。


This comment is better than not[h]ing, but still way too terse.




根据一些人的标准,它比什么都糟糕 - 它是公然的

谎言!毕竟,OP的帖子的重点是这个函数

做/不做/做包装。至少,不是这样,他可以看到它。 :) A

更好的评论本来是


/ *试图做文字包装* /


其次是解释为什么以及如何实际/不成功。

如果OP曾试图写下该错误的描述,他可能会给b
$ b发现(一些)他自己的问题,没有外面的

需要帮助!


HTH,

-Arthur



By some people''s standards, it''s worse than nothing---it''s a blatant
lie! After all, the whole point of the OP''s post was that this function
does /not/ do word wrapping. At least, not so he could "see" it. :) A
better comment would have been

/* Tries to do wordwrapping */

followed by an explanation of why and how it actually /doesn''t/ succeed.
If the OP had tried to write down a description of the bug, he probably
would have discovered (some of) the problems on his own, with no outside
help required!

HTH,
-Arthur


这篇关于简单的自动换行问题不包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆