求解C++的一道有关于string的题(英文)

求解C++的一道有关于string的题(英文)
Write a recursive function that display string reversly on the console using the following header:

void reverseDisplay(const char * const s)

For example, reverse("abcd") displays "dcba".


提示
The variable s is a c-string, the same as char s[].
To get the length of the string s, you can 1) use the library function strlen(), or 2) write a code to determine the length by yourself.
Please remember to include is you want use c-string library functions like strlen.
子水各 1年前 已收到1个回答 举报

zddygc 春芽

共回答了18个问题采纳率:83.3% 举报

#include
#include

using namespace std;
void reverseDisplay(const char * const s);

void main()
{
x09char s[50] = "abcd";
reverseDisplay(s);
}

void reverseDisplay(const char * const s)
{
x09int leng = 0;
x09int i;
x09char * buff = NULL;

x09leng = strlen(s);
x09buff = new char[leng+1];

x09for(i=0; ix09{
x09x09buff[i] = s[leng-1-i];
x09}
x09buff[i] = '';
x09cout<x09delete buff;
}

1年前

2
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.469 s. - webmaster@yulucn.com