CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Oct 2011
    Posts
    27

    Resolved

    Resolved
    Last edited by Gregor007; February 20th, 2012 at 12:20 PM. Reason: Resolved

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    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?

  3. #3
    Join Date
    Oct 2011
    Posts
    27

    Re: Function which finds the given word in the line

    Quote Originally Posted by GCDEF View Post
    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;    }
    }

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Function which finds the given word in the line

    Quote Originally Posted by Gregor007 View Post
    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.

  5. #5
    Join Date
    Oct 2011
    Posts
    27

    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'

  6. #6
    Join Date
    May 2002
    Location
    Lindenhurst, NY
    Posts
    867

    Re: Function which finds the given word in the line

    Quote Originally Posted by Gregor007 View Post
    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

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Function which finds the given word in the line

    Quote Originally Posted by Gregor007 View Post
    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.

  8. #8
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Function which finds the given word in the line

    Quote Originally Posted by Gregor007 View Post
    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

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Function which finds the given word in the line

    Quote Originally Posted by D_Drmmr View Post
    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?

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Function which finds the given word in the line

    Quote Originally Posted by GCDEF View Post
    How did my name get in your quote?
    Well, I guess, D_Drmmr is just a wizard!
    Victor Nijegorodov

  11. #11
    Join Date
    Apr 2007
    Posts
    162

    Re: Function which finds the given word in the line

    Quote Originally Posted by GCDEF View Post
    Who is controlling the quotes
    I'm confused!

  12. #12
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Function which finds the given word in the line

    Quote Originally Posted by GCDEF View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured