I have this assignment due and its a bit tricky, i was wondering how is it possible to incoporate both C-string and a string object at the same time. Any help would be very very appreciated. thank you all in advance. Here is the actual problem from the book.

Write a function that accepts either a pointer to a C-string, or a string object, as its argument. The function should return the character that appears most frequently in the string. Demonstrate the function in a complete program.

My teacher usually has us do this is seperate .cpp files because its easier to go back and fix things. which is nice but a bit more confusing sometimes. He also likes us to use a .h file and include it in any .cpp files that will need it. Just thought id let you guys know if this is gonna help or if it would matter or anything.

thanks again,
SB

Edited 5 Years Ago by ShadowBorn: n/a

Well what do you have so far? As far as using a c-string or a string object you can have you function take in a char * and then convert it to a string like

void foo(const char * bar)
{
    string temp(bar);
    // do stuff
}

As far as the functionality of the program you might want to look into the count function in the <algorithms> header. you can find a good link here.

Thank you very much for your help Nathan, the website you suggested seemed to help a bit with other questions i had as well. The little snippet you had helped as well. Thank you very much. I'm quite new to this and i appreciate all the help

This article has been dead for over six months. Start a new discussion instead.