CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 20

Threaded View

  1. #11
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Counting characters help

    Quote Originally Posted by LogicWavelength View Post
    I know that two functions is totally unnecessary - but the book's assignment specifically states to make two.
    Programming is an exact science -- if the description says two separate functions:
    Code:
    int countVowels(const char* userInput)
    {
       return countHelper(userInput, "aeiou");
    }
    
    int countConsonants(const char* userInput)
    {
       return countHelper(userInput, "bcdfghjklmnpqrstvwxyz");
    }
    countHelper is the function I mentioned in my post. See, two separate functions. Also, a good beginner programmer would see that there is redundancy, and would have done something similar to what I wrote above.
    Would this be what you're asking for:
    Code:
    for(int foo = 0; foo < vowel; foo++)
    No.

    There is a library function called strchr() that seaches for a character in a string. I suggest you use it instead of writing another loop.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; April 5th, 2011 at 10:05 AM.

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