文本编辑器 [英] text editor

查看:115
本文介绍了文本编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

我已经开始了我的第一个大项目。我是一个新手,毫无疑问......当我用b b b b b b b b b b we we we we we we we we we we we we we we we we we we we we we we we但是

无论如何,我试图重新制作记事本(Windows XP)。当然,它不会是好的b $ b。但我要做的是一个小程序,可以在一个字符串中存储
块文本,然后将该字符串保存到磁盘。我的

问题是我无法接受我的规格输入。例如:

''我爱节目''必须存储为''我',''\\'0'','''',''o'',''v '',''e'',

''\''',''p'',''r'',''o'',''g'',' 'r'',''a',''m'','s'',''\ r''(你可以观察到

那个相当不同的''\ r ''在整个字符串之后....我希望这是一个

标志的说法....

"''这是字符串的结尾'就像''\ 0''在普通字符串中所做的那样。

这里唯一不同的是我想将句子存储在字符串中

而不是单词。)i已经尝试过了......这就是我所做的 -


char g;

for(int p = 0; p< 1000; p ++)

{

while((g = getche())!=''\ r '')

{str [p] = g;}

if(g =''\ r''){break; }

}


您可能已经猜到了,它没有工作!

请帮帮我。

解决方案

" MC felon"写道:


我已经开始了我的第一个大项目。我是一个新手,毫无疑问......当我用b b b b b b b b b b we we we we we we we we we we we we we we we we we we we we we we we但是

无论如何,我试图重新制作记事本(Windows XP)。当然,它不会是好的b $ b。但我要做的是一个小程序,可以在一个字符串中存储
块文本,然后将该字符串保存到磁盘。我的

问题是我无法接受我的规格输入。例如:

''我爱节目''必须存储为''我',''\\'0'','''',''o'',''v '',''e'',

''\''',''p'',''r'',''o'',''g'',' 'r'',''a',''m'','s'',''\ r''(你可以观察到

那个相当不同的''\ r ''在整个字符串之后....我希望这是一个

标志的说法....

"''这是字符串的结尾'就像''\ 0''在普通字符串中所做的那样。

这里唯一不同的是我想将句子存储在字符串中

而不是单词。)i已经尝试过了......这就是我所做的 -


char g;

for(int p = 0; p< 1000; p ++)

{

while((g = getche())!=''\ r '')

{str [p] = g;}

if(g =''\ r''){break; }



您的意思是==而不是=?


}

你可能已经猜到了,它没有工作!

请帮帮我。



osmium写道:


" MC felon"写道:


if(g =''\ r''){break; }



您的意思是==而不是=?



养成防止此类事情的好习惯(除了将编译器放在最高警告级别并使用lint之外) -like

程序来监视这类事情)是将常量放在第一位:


if(''\''= g)/ /编译错误!应该是==


干杯! --M




mlimber写道:


osmium写道:


" MC felon"写道:


if(g =''\ r''){break; }



您的意思是==而不是=?



养成防止此类事情的好习惯(除了将编译器放在最高警告级别并使用lint之外) -like

程序来监视这类事情)是将常量放在第一位:


if(''\''= g)/ /编译错误!应该是==


干杯! --M



非常感谢!

所以你认为它会起作用吗?以及如何将''\ r''分配给一个字符和

然后将其附加到字符串(表示EOL(行尾))??


hi.
i have started on my first big project. i''m a newbee, no doubt... when
i compare the things i make with the things you people program. But
anyway, i''m attempting to re-make notepad (of windows XP). It wont be
as good, of course. But what i''ll make is a tiny program that can store
blocks of text in one string and then save this string to disk. my
problem is that i''m not able to take input for my specifications. ex:
''i love programs'' must be stored as ''i'', ''\0'', ''l'', ''o'', ''v'', ''e'',
''\0'', ''p'', ''r'', ''o'', ''g'', ''r'', ''a'', ''m'', ''s'', ''\r'' (you may observe
that rather distinct ''\r'' after the whole string.... I want that as a
sign of saying....
"that''s the end of the string" just like ''\0'' does in ordinary strings.
only difference here is that i want to store sentences in a string
rather than words.)

i have, of course, tried my hand at it.... and this is what i cooked-

char g;
for(int p = 0;p<1000;p++)
{
while((g = getche()) != ''\r'')
{ str[p] = g;}
if(g = ''\r'') { break; }
}

as you may have guessed, it DOESNT WORK!
please help me out.

解决方案

"MC felon" wrote:

i have started on my first big project. i''m a newbee, no doubt... when
i compare the things i make with the things you people program. But
anyway, i''m attempting to re-make notepad (of windows XP). It wont be
as good, of course. But what i''ll make is a tiny program that can store
blocks of text in one string and then save this string to disk. my
problem is that i''m not able to take input for my specifications. ex:
''i love programs'' must be stored as ''i'', ''\0'', ''l'', ''o'', ''v'', ''e'',
''\0'', ''p'', ''r'', ''o'', ''g'', ''r'', ''a'', ''m'', ''s'', ''\r'' (you may observe
that rather distinct ''\r'' after the whole string.... I want that as a
sign of saying....
"that''s the end of the string" just like ''\0'' does in ordinary strings.
only difference here is that i want to store sentences in a string
rather than words.)

i have, of course, tried my hand at it.... and this is what i cooked-

char g;
for(int p = 0;p<1000;p++)
{
while((g = getche()) != ''\r'')
{ str[p] = g;}
if(g = ''\r'') { break; }

Did you mean == instead of = ?

}

as you may have guessed, it DOESNT WORK!
please help me out.



osmium wrote:

"MC felon" wrote:

if(g = ''\r'') { break; }


Did you mean == instead of = ?

A good habit to get into to prevent this sort of thing (besides putting
your compiler on the highest warning level and using a lint-like
program to watch for this sort of thing) is to put constants first:

if( ''\r'' = g ) // Compile error! Should be ==

Cheers! --M



mlimber wrote:

osmium wrote:

"MC felon" wrote:

if(g = ''\r'') { break; }

Did you mean == instead of = ?


A good habit to get into to prevent this sort of thing (besides putting
your compiler on the highest warning level and using a lint-like
program to watch for this sort of thing) is to put constants first:

if( ''\r'' = g ) // Compile error! Should be ==

Cheers! --M

Thanks a lot!
so do you think it will work? and how do i assign ''\r'' to a char and
then attach it to the string (to signify the EOL (end of line)) ??


这篇关于文本编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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