Dears! My name is Caroline and I come from Poland.
I am looking for help in my C++ problem. Sorry for my poor English, I hope You will understand me.

This is my problem: I have to make some program:
Make a recursive function which have a parameter - array of chars. This function have to change order of chars: first becomes last, second - last but one etc. Then, I have to write some simple program with this function.

Could You help me? :*

Recommended Answers

All 4 Replies

Forgive me writing post under post...

void x (char* a, int b)
{
if (b == 0 | b == 1) return;
char c = a[0];
a[0] = a[b-1];
a[b-1] = c;
x(a+1, b-2);
}

Why DevC++ Builder shows me "too few arguments to function x(char*, int) ??

I don't know why you get that error, your function is calling itself correctly. Perhaps you're getting that error at the point where your originally call the function from your test program?

One error, in the if clause, you need to use two | to represent OR, as in if( b == 1 || b == 0 ) Fix that, and I find it works OK.

And your English is fine, better than some of the native speakers on this forum.

Much better than my Polish.

I too can see nothing wrong in your code (syntactically) except the thing what vmanes did already mention ...

This function have to change order of chars: first becomes last, second - last but one etc. Then, I have to write some simple program with this function.

Actually that's the same as: Write a function which uses recursion to reverse a c-string ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.