Howdy, I am trying to create a function in which i compares two words and sees if one is present in the other and output the remaining word at that occurrence, any help will be greatly appreciated. Here is what i have so far.
//------------------------------------------------------------------------------
istream& read_word(istream& is, char* buffer, int max)
// read at most max-1 characters from is into buffer
{
is.width(max); // read at most max-1 characters in the next >>
is >> buffer; // read whitespace terminated word,
// add zero after the last character read into p
return is;
}
//------------------------------------------------------------------------------
istream& read_word_2(istream& is, char* buffer, int max)
// read at most max-1 characters from is into buffer
{
is.width(max); // read at most max-1 characters in the next >>
is >> buffer; // read whitespace terminated word,
// add zero after the last character read into p
return is;
}
//------------------------------------------------------------------------------
int main()
{
const int max = 128;
char s[max];
char x[max];
cout<<"Please type in two word and ill see if one of your words is contained in\n";
cout<<"in the other and output the rest of the word in which it occurred\n";
while (read_word(cin,s,max)&&read_word_2(cin,x,max)){
I failed to mention that i cant use the standard library, the goal of this code is to correctly implement arrays and pointers. Well here is my updated code. It just outputs the second word entered and not the remainder of the other word.
Also i understand i don't want the answer handed to me, all i want is for someone to clarify on what Im having issues with.
/* ========================================================================== */
string word_s=s;// sets the first word entered to word_s
string word_x=x;// sets the second word entered to word_x
for(int i=0;i<word_s.length();++i) { //copies char s into copy_s[] array
copy_s[i]=*s;
++s;
//cout<<copy_s[i];
}
for(int i=0;i<word_x.length();++i){ //copies char s into copy_x[] array
copy_x[i]=*x;
++x;
//cout<<copy_x[i];}
}
for(int i = 0; i<word_x.length();++i){
if(copy_s[i]!=copy_x[i]){// outputs x(question asks print it at the first accurance)
} //Part im stuck on
else
cout<<copy_s[i];
}
}
//------------------------------------------------------------------------------
istream& read_word(istream& is, char* buffer, int max)
// read at most max-1 characters from is into buffer
{
is.width(max); // read at most max-1 characters in the next >>
is >> buffer; // read whitespace terminated word,
// add zero after the last character read into p
return is;
}
//------------------------------------------------------------------------------
istream& read_word_2(istream& is, char* buffer, int max)
// read at most max-1 characters from is into buffer
{
is.width(max); // read at most max-1 characters in the next >>
is >> buffer; // read whitespace terminated word,
// add zero after the last character read into p
return is;
}
//------------------------------------------------------------------------------
int main()
{
const int max = 128;
char s[max];
char x[max];
cout<<"Please type in two word and ill see if one of your words is contained in\n";
cout<<"in the other and output the rest of the word in which it occurred\n";
while (read_word(cin,s,max)&&read_word_2(cin,x,max)){// read in both words