Thread: 1 quick question

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    62

    1 quick question

    what does this mean
    Code:
        ch = getch();
                    while(ch !='\r')
    	{
    	pass[i]=ch;
    	printf("*");
    	i++;
    	ch = getch();
    	  }

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    gets a char from input buffer, as long as its not a '\r' character it stores that character in an array and then prints * to the screen, increments index, and gets another char. It keeps going until the user enters '\r'.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    It means someone doesn't know how to indent properly.
    Was it written by Pablo Picasso?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Registered User ch4's Avatar
    Join Date
    Jan 2007
    Posts
    154
    pass Array can't be unlimited.
    You store until \r but what about reading a paragraph with 1000 letters ?
    Is your array ready to store ?

  5. #5
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by ch4 View Post
    pass Array can't be unlimited.
    You store until \r but what about reading a paragraph with 1000 letters ?
    Is your array ready to store ?
    Yes, okay, a buffer overflow is a possibility here, there should be some sort of limiting condition on the loop. However, this code is clearly intended to mask a password as it's being entered. I doubt anyone will enter a password more than, say, 20 chars long.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by QuantumPete
    However, this code is clearly intended to mask a password as it's being entered. I doubt anyone will enter a password more than, say, 20 chars long.
    Famous last words before an attacker exploits a buffer overflow vulnerability?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Hacker MeTh0Dz's Avatar
    Join Date
    Oct 2008
    Posts
    111
    Indeed.

  8. #8
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by laserlight View Post
    Famous last words before an attacker exploits a buffer overflow vulnerability?
    :P Indeed! Which is why I suggested a limiting condition on the loop. check that the char != 'r' and i < 20 or something.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM