两个小问题...... [英] Two small problems...

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

问题描述

大家好!

我对C ++很陌生,所以我无法弄清楚如何写这些

两个函数:

编写一个带有两个参数的函数,一个是C字符串,另一个是一个

字符,并找出字符串出现在C字符串中的次数。

无论是递归方式还是非递归方式。

我知道这对你们来说是个小菜一碟,但我只是试图从Java中将
跳入C ++,并且因为我不太熟悉C $ / $
约定,我以为我得到了算法,但他们只是没有正确运行

...谢谢你你的帮助!


依旧,



Hi all!
I am quite new to C++, so I could not figure out how to write these
two functions:
Write a function with two parameters, one is a C-string, another is a
char, and find out how many times the char appear in the C-string.
Both recursive way and non-recursive way.
I know it''s a piece of cake for you guys, but I just tried to jump
into C++ from Java, and because I wasn''t quite familiar with the C
convention, I thought I got the algorithm but they just didn''t run
correctly... Thank you for your helps!

SIncerely,
Ben

推荐答案

2007年4月7日23:35:36 -0700 comp.lang.c ++,Benny Van

< fy ******** @ gmail.comwrote,
On 7 Apr 2007 23:35:36 -0700 in comp.lang.c++, "Benny Van"
<fy********@gmail.comwrote,

>我以为我得到了算法,但他们只是没有正确运行
...
>I thought I got the algorithm but they just didn''t run
correctly...



Marshall Cline的C ++ FAQ中包含了这个问题。请参阅主题

" [5.8]如何发布有关无法正常工作的代码的问题?&b
?在发布之前查看常见问题总是好的。

您可以在以下网址阅读常见问题解答:
http://www.parashift.com/c++-faq-lite/


" Benny Van < fy ******** @ gmail.com写信息

新闻:11 ********************* @ n59g2000hsh.googlegro ups.com ...
"Benny Van" <fy********@gmail.comwrote in message
news:11*********************@n59g2000hsh.googlegro ups.com...

大家好!

我对C ++很陌生,所以我无法弄清楚写这些

两个函数:

用两个参数写一个函数,一个是C字符串,另一个是

字符,以及找出字符串出现在C字符串中的次数。

递归方式和非递归方式。

我知道这对你来说是小菜一碟伙计们,但我只是试图从Java中跳转到$ C $ b,因为我不太熟悉C $ / $
约定,我以为我得到了算法但是他们只是没有正确地运行

...谢谢你的帮助!
Hi all!
I am quite new to C++, so I could not figure out how to write these
two functions:
Write a function with two parameters, one is a C-string, another is a
char, and find out how many times the char appear in the C-string.
Both recursive way and non-recursive way.
I know it''s a piece of cake for you guys, but I just tried to jump
into C++ from Java, and because I wasn''t quite familiar with the C
convention, I thought I got the algorithm but they just didn''t run
correctly... Thank you for your helps!



告诉我们你的尝试。

Show us what you tried.


Benny Van写道:
Benny Van wrote:

大家好!

我对C ++很陌生,所以我无法弄清楚如何编写这些

两个函数:

用两个参数编写一个函数,一个是C字符串,另一个是
字符,并找出字符串出现在C字符串中的次数。

递归方式和非递归方式。

我知道这对你们来说是个小菜一碟,但我只是试着将b $ b跳到C ++中来自Java,因为我不太熟悉C

约定,我以为我得到了算法,但他们只是没有正确运行

..谢谢你的帮助!


依旧,

Ben
Hi all!
I am quite new to C++, so I could not figure out how to write these
two functions:
Write a function with two parameters, one is a C-string, another is a
char, and find out how many times the char appear in the C-string.
Both recursive way and non-recursive way.
I know it''s a piece of cake for you guys, but I just tried to jump
into C++ from Java, and because I wasn''t quite familiar with the C
convention, I thought I got the algorithm but they just didn''t run
correctly... Thank you for your helps!

SIncerely,
Ben



按照之前给出的建议是一个良好的开端。让我添加一些

的提示和暗示性问题,万一你真的不知道

从哪里开始。


1.如何迭代C字符串的字符?你怎么用
填写类似的东西:


for(char c =?;?;?)

做点什么c


让c迭代字符?


2.如何递归处理C字符串?考虑一个指向

字符串开头的指针。现在假设你推进了那个指针。是什么

它还指向一个C字符串?你怎么知道这个递归何时结束?

Following the previously given advice is a good start. Let me add a few
hints and suggestive questions just in case you truly don''t know where
to begin.

1. How do you iterate over the characters of a C-string? How would you
fill in something like:

for( char c = ?; ?; ?)
do something with c

to make c iterate over the characters?

2. How do you process a C-string recursively? Consider a pointer to the
beginning of a string. Now suppose you advance that pointer. Is what
it points to still a C-string? How do you know when this recursion ends?


这篇关于两个小问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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