1 quick question

This is a discussion on 1 quick question within the C Programming forums, part of the General Programming Boards category; what does this mean Code: ch = getch(); while(ch !='\r') { pass[i]=ch; printf("*"); i++; ch = getch(); }...

  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
    ch4
    ch4 is offline
    Newbeer ch4's Avatar
    Join Date
    Jan 2007
    Posts
    142
    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
    22,121
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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-27-2005, 12:05 AM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 04:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 05:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 12:04 PM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 06:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21