Re: Function which finds the given word in the line
What does L1 do and what's the point of the space?
What's the point of punctuation?
Why do you need a while loop?
What happens if the word isn't in the line?
Wouldn't it make more sense to return wbgn rather than pass it in as an output parameter?
Did you test it? What happened?
Re: Function which finds the given word in the line
Quote:
Originally Posted by
GCDEF
What's the point of punctuation?
It was in the task. "void FindWord(string line, string punctuation, string givenWord, int & beginning)"
Code:
void FindWord(string line, string givenWord, int & wbgn)
{
int wbgn = line.find(givenWord, 0);
if (wbgn > -1) {
return wbgn; }
else {
return -1; }
}
Re: Function which finds the given word in the line
Quote:
Originally Posted by
Gregor007
It was in the task. "void FindWord(string line, string punctuation, string givenWord, int & beginning)"
Code:
void FindWord(string line, string givenWord, int & wbgn)
{
int wbgn = line.find(givenWord, 0);
if (wbgn > -1) {
return wbgn; }
else {
return -1; }
}
Learning good indentation practices will make your life as a programmer easier.
Code:
void FindWord(string line, string givenWord, int & wbgn)
{
int wbgn = line.find(givenWord, 0);
if (wbgn > -1)
{
return wbgn;
}
else
{
return -1;
}
}
That looks closer but what does your compiler tell you about that code?
Re: Function which finds the given word in the line
1 error(s), 0 warning(s)
Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
error C2082: redefinition of formal parameter 'wbgn'
Re: Function which finds the given word in the line
Quote:
Originally Posted by
Gregor007
1 error(s), 0 warning(s)
Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
error C2082: redefinition of formal parameter 'wbgn'
http://lmgtfy.com/?q=error+C2082%3A+...rmal+parameter
Re: Function which finds the given word in the line
Quote:
Originally Posted by
Gregor007
1 error(s), 0 warning(s)
Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
error C2082: redefinition of formal parameter 'wbgn'
I'm surprised that's the only error. You have a void function returning a value too.
If you are going to return the result, and to me that's the more appropriate way to do it than pass in an output parameter, the function needs to be defined as an int, and you need to drop the wbgn argument.
Re: Function which finds the given word in the line
Quote:
Originally Posted by
Gregor007
Is this function ok? Do I have to find the end of the word as well?
What is the result when you search for the word "at" in the line "What does punctuation do?"?
Re: Function which finds the given word in the line
Quote:
Originally Posted by
D_Drmmr
What is the result when you search for the word "at" in the line "What does punctuation do?"?
How did my name get in your quote?
Re: Function which finds the given word in the line
Quote:
Originally Posted by
GCDEF
How did my name get in your quote?
Well, I guess, D_Drmmr is just a wizard! ;)
Re: Function which finds the given word in the line
Quote:
Originally Posted by
GCDEF
Who is controlling the quotes
I'm confused!
Re: Function which finds the given word in the line
Quote:
Originally Posted by
GCDEF
How did my name get in your quote?
Sorry, I think I did a multiquote and then messed up. I edited my post to change it back.