|
-
January 25th, 2012, 08:17 AM
#1
Resolved
Last edited by Gregor007; February 20th, 2012 at 12:20 PM.
Reason: Resolved
-
January 25th, 2012, 08:25 AM
#2
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?
-
January 25th, 2012, 09:21 AM
#3
Re: Function which finds the given word in the line
 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; }
}
-
January 25th, 2012, 09:31 AM
#4
Re: Function which finds the given word in the line
 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?
Last edited by GCDEF; January 25th, 2012 at 09:35 AM.
-
January 25th, 2012, 11:27 AM
#5
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'
-
January 25th, 2012, 12:26 PM
#6
Re: Function which finds the given word in the line
 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
-
January 25th, 2012, 12:29 PM
#7
Re: Function which finds the given word in the line
 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.
-
January 25th, 2012, 12:31 PM
#8
Re: Function which finds the given word in the line
 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?"?
Last edited by D_Drmmr; January 26th, 2012 at 03:26 PM.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
January 25th, 2012, 12:52 PM
#9
Re: Function which finds the given word in the line
 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?
-
January 25th, 2012, 01:37 PM
#10
Re: Function which finds the given word in the line
 Originally Posted by GCDEF
How did my name get in your quote?
Well, I guess, D_Drmmr is just a wizard!
Victor Nijegorodov
-
January 25th, 2012, 02:34 PM
#11
Re: Function which finds the given word in the line
 Originally Posted by GCDEF
Who is controlling the quotes
I'm confused!
-
January 26th, 2012, 03:26 PM
#12
Re: Function which finds the given word in the line
 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.
Last edited by D_Drmmr; January 26th, 2012 at 03:30 PM.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|