缺少removeStr和substr函数 [英] Missing removeStr and substr function

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

问题描述

大家好!


我买了这本书用C语言编程。作者:Stephen G Kochan。我在他的网站上想念2

答案。

(removedtr和substr函数)如何实现这些

函数?如果有人可以帮助我,那将是很棒的,因为

Stephen Kochan无法到达。


感谢您的帮助


T. Felb

Hi all!

I bought the book "Programming in C" by Stephen G Kochan. I miss 2
answers at his website.
(removestr and the substr function) How can I implement these
functions? It would be wonderful if someone can help me out, because
Stephen Kochan is not reachable.

Thanks for any help

T. Felb

推荐答案

11月26日下午1:05,tfelb< tomico ... @ gmail .comwrote:
On Nov 26, 1:05 pm, tfelb <tomico...@gmail.comwrote:

大家好!


我买了这本书Programming in C作者:Stephen G Kochan。我在他的网站上想念2

答案。

(removedtr和substr函数)如何实现这些

函数?如果有人可以帮助我,那将是非常好的,因为

Stephen Kochan无法联系到。
Hi all!

I bought the book "Programming in C" by Stephen G Kochan. I miss 2
answers at his website.
(removestr and the substr function) How can I implement these
functions? It would be wonderful if someone can help me out, because
Stephen Kochan is not reachable.



虽然我不熟悉Kochan先生的书或他的功能,但我可以猜测他们是怎么回事实现。事实上,除非Kochan先生已经确定了某种令人费解的处理要求,否则

函数应该很简单,以至于对任何人来说都是显而易见的

,即使是C,字符数组的经验也很少,

字符串的定义。


为什么不发布对这两个函数的要求,以及

到目前为止你编写的代码,我们将看看我们是否可以帮助你

正确完成。


While I''m not familiar with Mr. Kochan''s book or his functions, I can
guess how they might be implemented. In fact, unless Mr. Kochan has
dictated some sort of convoluted processing requirement, both
functions should be simple to the point of being obvious to anyone
with even a small amount of experience with C, character arrays, and
the definition of a string.

Why don''t you post the requirements for both of these functions, and
the code you''ve written so far, and we''ll see if we can assist you in
getting it right.


11月26日19:13,Lew Pitcher< lpitc ... @ teksavvy.comwrote:
On 26 Nov., 19:13, Lew Pitcher <lpitc...@teksavvy.comwrote:

11月26日下午1:05,tfelb< tomico ... @ gmail.comwrote:
On Nov 26, 1:05 pm, tfelb <tomico...@gmail.comwrote:

大家好!
Hi all!


我买了这本书Programming in C作者:Stephen G Kochan。我在他的网站上想念2

答案。

(removedtr和substr函数)如何实现这些

函数?如果有人可以帮助我,那将是非常好的,因为

Stephen Kochan无法联系到。
I bought the book "Programming in C" by Stephen G Kochan. I miss 2
answers at his website.
(removestr and the substr function) How can I implement these
functions? It would be wonderful if someone can help me out, because
Stephen Kochan is not reachable.



虽然我不熟悉Kochan先生的书或他的功能,但我可以猜测他们是怎么回事实现。事实上,除非Kochan先生已经确定了某种令人费解的处理要求,否则

函数应该很简单,以至于对任何人来说都是显而易见的

,即使是C,字符数组的经验也很少,

字符串的定义。


为什么不发布对这两个函数的要求,以及

到目前为止你编写的代码,我们将看看我们是否可以帮助你

正确完成。


While I''m not familiar with Mr. Kochan''s book or his functions, I can
guess how they might be implemented. In fact, unless Mr. Kochan has
dictated some sort of convoluted processing requirement, both
functions should be simple to the point of being obvious to anyone
with even a small amount of experience with C, character arrays, and
the definition of a string.

Why don''t you post the requirements for both of these functions, and
the code you''ve written so far, and we''ll see if we can assist you in
getting it right.



这些是Stephen G Kochan在他的网站上发布的功能,但

来回答我的书籍问题我错过了substr和removedtr功能

了解这些函数是如何实现的。


int findString(const char source [],const char s [])

{

int i,j,foundit = false;


//尝试源中的每个角色


for(i = 0; source [i]!=''\ 0''&&!foundit; ++ i){

foundit = true;

//现在看看来自s的相应字符是否匹配


for(j = 0; s [j]!=''\'''&& foundit; ++ j)

if(source [j + i]!= s [j] || source [j + i] ==''\ 0'')

foundit = false;


if(foundit)

返回i;

}


返回-1;

}


10-7

/ *将字符串s插入字符串源从我开始/>
这个函数使用了章节中定义的stringLength函数




注意:这个函数假设源足够大

来存储插入的字符串(危险!)* /


void insertString(char source [],char s [],int i)

{

int j,lenS,lenSource;


/ *首先,找出这两个字符串有多大* /

lenSource = stringLength(source);

lenS = stringLength(s);


/ *健全性检查 - 注意i = = lenSource

有效地将s连接到源的末尾* /


if(i lenSource)

return;


/ *现在我们必须从插入点移动源中的字符

为s腾出空间。

注意我们复制从结尾开始的字符串

以避免覆盖源代码中的字符。

我们还复制终止空值(j从lenS开始)

和我们一样ll因为最终结果必须为空终止* /


for(j = lenSource; j> = i; --j)

来源[lenS + j] =来源[j];


/ *我们已经腾出空间,现在复制到源头在

插入点* /


for(j = 0; j< lenS; ++ j)

source [j + i] = s [j];

}


10-9

bool replaceString(char source [] ,char s1 [],char s2 [])

{

int index;


//首先找到s1里面的s1来源


index = findString(source,s1);


if(index == -1)

返回false;


//现在从源中删除s1

removeString(source,index,stringLength(s1));


//现在插入新字符串


insertString(source,s2,index);


返回true;

}

These are the functions of Stephen G Kochan posted on his website, but
to answer my book questions I miss the substr and removestr function
to understand how these functions are implemented.

int findString (const char source[], const char s[])
{
int i, j, foundit = false;

// try each character in source

for ( i = 0; source[i] != ''\0'' && !foundit; ++i ) {
foundit = true;

// now see if corresponding chars from s match

for ( j = 0; s[j] != ''\0'' && foundit; ++j )
if ( source[j + i] != s[j] || source[j + i] == ''\0'' )
foundit = false;

if (foundit)
return i;
}

return -1;
}

10-7
/* insert string s into string source starting at i
This function uses the stringLength function defined
in the chapter.

Note: this function assumes source is big enough
to store the inserted string (dangerous!) */

void insertString (char source[], char s[], int i)
{
int j, lenS, lenSource;

/* first, find out how big the two strings are */

lenSource = stringLength (source);
lenS = stringLength (s);

/* sanity check here -- note that i == lenSource
effectively concatenates s onto the end of source */

if (i lenSource)
return;

/* now we have to move the characters in source
down from the insertion point to make room for s.
Note that we copy the string starting from the end
to avoid overwriting characters in source.
We also copy the terminating null (j starts at lenS)
as well since the final result must be null-terminated */

for ( j = lenSource; j >= i; --j )
source [lenS + j] = source [j];

/* we''ve made room, now copy s into source at the
insertion point */

for ( j = 0; j < lenS; ++j )
source [j + i] = s[j];
}

10-9
bool replaceString (char source [], char s1[], char s2[])
{
int index;

// first locate s1 inside the source

index = findString (source, s1);

if ( index == -1 )
return false;

// now delete s1 from the source

removeString (source, index, stringLength (s1));

// now insert the new string

insertString (source, s2, index);

return true;
}


tfelb写道:
tfelb wrote:

嗨全部!


我买了这本书用C语言编程。作者:Stephen G Kochan。我在他的网站上想念2

答案。

(removedtr和substr函数)如何实现这些

函数?如果有人可以帮助我,那将是非常好的,因为

Stephen Kochan无法联系到。
Hi all!

I bought the book "Programming in C" by Stephen G Kochan. I miss 2
answers at his website.
(removestr and the substr function) How can I implement these
functions? It would be wonderful if someone can help me out, because
Stephen Kochan is not reachable.



简单的Google搜索产生

< http://csourcesearch.net/package/fk/0.6.7/fk-0.6 .7 / lib / removedtr.c>

< http://www.koders.com/c/fid88DBABDF4CD01D6FBE11E7B5CB60CC2BEA98E60B.aspx>


我做了没有努力检查代码的质量。

在任何情况下,comp.lang.c都不是一个想要的新闻组,并且

_are_这样的新闻组。试一下。

A simple Google search yields
<http://csourcesearch.net/package/fk/0.6.7/fk-0.6.7/lib/removestr.c>
<http://www.koders.com/c/fid88DBABDF4CD01D6FBE11E7B5CB60CC2BEA98E60B.aspx>

I have made no effort to check the quality of the code.
In any case, comp.lang.c is not a sources-wanted newsgroup, and there
_are_ such newsgroups. Try one.


这篇关于缺少removeStr和substr函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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