Computer Science Canada Please help with String |
Author: | tinhnho [ Tue Feb 24, 2004 11:25 pm ] | ||||
Post subject: | Please help with String | ||||
Write the following member function: // strcmp is negative if s < s1 // is 0 if s == s1 // and positive if s > s1 // where s is the emplicite argument int my_string::strcmp(const my_string& s1); // strrev reverses the my_string void my_string::strrev(); //print oeverloaded to print the frist n characters void my_string:: print(int n); here is what i got so far:
when i compile it ,the compiler telling me the error: " No matching function for call to my_string::print()" and "Candidates are : void my_string::print()".Please tell me where did i go wrong,thanks alot Note:
Can not use predefined strrev function. |
Author: | Tony [ Wed Feb 25, 2004 1:07 am ] | ||
Post subject: | |||
eh... looks complicated... isn't there already string.compare() function? or is that java? anyways, its something like
I think basically you just keep on comparing one character at a time (using substrings) untill you find pair that is different... or run out of characters - then strings are the same. |
Author: | wtd [ Wed Feb 25, 2004 1:28 am ] |
Post subject: | |
It's C++, and the problem is that you've defined the print function to take one argument of type int, yet when you call it, you call it without arguments. |
Author: | tinhnho [ Wed Feb 25, 2004 9:33 am ] | ||
Post subject: | |||
wtd wrote: It's C++, and the problem is that you've defined the print function to take one argument of type int, yet when you call it, you call it without arguments.
should i go for this:
|
Author: | Tony [ Wed Feb 25, 2004 10:47 am ] |
Post subject: | |
tinhnho - a void function cannot have a return statement |
Author: | tinhnho [ Wed Feb 25, 2004 12:55 pm ] |
Post subject: | |
my bad,it should not have statemen in there |
Author: | tinhnho [ Wed Feb 25, 2004 6:45 pm ] | ||
Post subject: | |||
here is what i have done.I compiled it and it said something about run time error , there are no message error.I'm using Dev C++.Thanks
|
Author: | wtd [ Wed Feb 25, 2004 7:07 pm ] | ||
Post subject: | |||
Hopefully the following will prove educational. I cleaned it up quite a bit.
|