字符串连接使用递归 [英] String concat using Recursion

查看:110
本文介绍了字符串连接使用递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


可以告诉我如何使用递归来连接两个字符串。

以及如何使用递归修剪字符串。(在C,offcourse)


问候,

Raman Chalotra

Hi All,

Could any one tell me How to concatenate two strings using recursion.
And also how to trim a string using recursion.(in C, offcourse)

Regards,
Raman Chalotra

推荐答案



Raman写道:

Raman wrote:

大家好,


任何人都可以告诉我如何使用递归来连接两个字符串。

以及如何使用递归修剪字符串。(在C中,offcourse)
Hi All,

Could any one tell me How to concatenate two strings using recursion.
And also how to trim a string using recursion.(in C, offcourse)



I会建议做自己的功课。


但我会给你一个提示。你通常需要迭代来执行这些函数,这是正确的吗?通常,在转换为递归函数时,您将传递数据结构作为参数。


I would recommend doing your own homework.

But I''ll give you a hint. You would normally need to iterate to perform
these functions, correct? Generally, you''ll pass the data structure you
iterate (over) as an argument, when translating to a recursive function.


2007年1月22日21:31:18 -0800,拉曼 < ra *********** @ gmail.com>

写道:
On 22 Jan 2007 21:31:18 -0800, "Raman" <ra***********@gmail.com>
wrote:

>大家好,

任何人都可以告诉我如何使用递归连接两个字符串。
>Hi All,

Could any one tell me How to concatenate two strings using recursion.



为什么你会想要这样做而不是使用标准C

函数strcat()?我会告诉你原因 - 永远不会。


如果这是一个教练提出的问题,那么说教师就是浪费你的时间。他或她应该关注与你应该做什么有关的问题,而不是与你有什么不相关的事情。

你应该做什么。


我会问教练我最喜欢的10个标准C问题,而且我会打赌他或她不会得到所有10个正确的问题。我警告你,不要叫我的

虚张声势:^)

Why would you ever want to do that instead of using the standard C
function strcat()? I''ll tell you why--never.

If this is a question posed by an instructor, then said instructor is
wasting your time. He or she should be focusing on the problems
related to what you should be doing instead of anything related to
what you shouldn''t be doing.

I''d ask the instructor my 10 favorite standard C quesdtions, and I''d
bet he or she wouldn''t get all 10 correct. I warn you, don''t call my
bluff :^)


>以及如何使用递归修剪字符串。 (在C,offcourse)
>And also how to trim a string using recursion.(in C, offcourse)



再次,为什么?


无论为什么,单词trim太模糊了,无法回答你的问题。在下面的程序中,我修剪了一个字符串,但你的想法

的修剪很可能与我的不同。


#include< stdio.h>

#define S" Hello the poor world - and rich!" ;

int main(无效)

{

char s [sizeof S] = S;

printf( 修剪前:%s \ n,s);

s [20] =''\ 0''; / * trim * /

printf( 修剪后:%s \ n,s);

返回0;

}


问候

-

jay

Again, why?

Regardless of why, the word "trim" is too vague to answer your
question. In the following program, I "trim" a string, but your idea
of "trim" most likely differs from mine.

#include <stdio.h>
#define S "Hello the poor world--and the rich!"
int main(void)
{
char s[sizeof S] = S;
printf("Before trim: %s\n", s);
s[20] = ''\0'';/*trim*/
printf("After trim: %s\n", s);
return 0;
}

Regards
--
jay


jaysome写道:
jaysome wrote:

2007年1月22日21:31:18 -0800,拉曼 < RA *********** @ gmail.com>
On 22 Jan 2007 21:31:18 -0800, "Raman" <ra***********@gmail.com>


任何人都可以告诉我如何使用递归连接两个字符串。
Could any one tell me How to concatenate two strings using recursion.



为什么你会想要这样做而不是使用标准C

函数strcat()?我会告诉你为什么 - 永远不会。


Why would you ever want to do that instead of using the standard C
function strcat()? I''ll tell you why--never.



标准库不可用的嵌入式系统?

embedded systems where the standard library isn''t available?


如果这样是一个教练提出的问题,然后说教练是浪费你的时间
。他或她应该专注于与你应该做的事情相关的问题,而不是与你不应该做的事情相关的任何事情。

你应该做的事情。
If this is a question posed by an instructor, then said instructor is
wasting your time. He or she should be focusing on the problems
related to what you should be doing instead of anything related to
what you shouldn''t be doing.



并不总是浪费时间。知道如何操纵字符串可能会在你遇到更难的问题时提供帮助你的标准是你好世界吗?是
a浪费时间。

not always a waste of time. Knowing how to manipulate strings might
help when you get a harder problem By your criteria "hello world" is
a waste of time.


我会问教练我最喜欢的10个标准C问题,而且我' 'd

打赌他或她不会得到所有10个正确的。我警告你,不要叫我的

诈唬:^)
I''d ask the instructor my 10 favorite standard C quesdtions, and I''d
bet he or she wouldn''t get all 10 correct. I warn you, don''t call my
bluff :^)



我们可以看到吗?

< snip>

-

Nick Keighley

could we see, please?
<snip>
--
Nick Keighley


无限多位不给你是100%准确度。你将只能代表代数数字。

Infinitely many bits doesn''t give you "100% accuracy". You will
only be able to represent the algebraic numbers.



当然,如果你使用其中一种只有

具有aleph-null-bit浮点的老式实现。任何体面的现代实施

应该提供至少aleph-one位。

(Bill Pursell和Keith Thompson clc)

Sure, if you use one of those old-fashioned implementations that only
has aleph-null-bit floating-point. Any decent modern implementation
should provide at least aleph-one bits.
(Bill Pursell and Keith Thompson clc)


这篇关于字符串连接使用递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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