Recursion problem with string

Pages: 12
I can see you changed your code. I think it was my bad, the formatting must have made me miss something, or maybe you've corrected it. Either way, the code is fine and will return how many characters are in the string.

However, I don't know what you mean by doing the second problem without your array. You want to find the location of the character, so you have to search through it. A string is already an array of characters.
Last edited on
I mean in the first problem I did'nt use an array is it possibile in the second?
You did use an array.

1
2
string s; //Declare a string - which holds a char array
s.substr(1); //Skip first element in the array 


The code for solving your second issue is already all over, just try/test them out.
Last edited on
std::string is an object that stores text, most likely in an array of char.
It makes no sense to write int lunghezza( std::string s ) for string has the member function length().

C-string is a convention to put null character as delimiter to the end of text that is in array of char.


Put other way, there is no sane way to store text without an array.


Note that for compiler these two declarations are identical:
1
2
int foo( char* bar );
int foo( char bar[] );

The 'bar' is a pointer. The [] of the second version is a mere hint for humans.
Topic archived. No new replies allowed.
Pages: 12