1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trapping keywords!

Discussion in 'C++' started by LuciferiA, Sep 8, 2009.

  1. LuciferiA

    LuciferiA New Member

    Joined:
    Sep 8, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    can someone help me how to trap keywords in a simple just a simple program..
    i have no idea about his..
    I'm just a newbie here in C++.. i need some introduction for C++..
    hope someone can help me!
    tnx in advance!
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    What does Trapping keywords mean ?
     
  3. LuciferiA

    LuciferiA New Member

    Joined:
    Sep 8, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    i mean.. if the program needs to input a number..
    then how can i disable all keywords? so that there will be no bug happen..
    ^_^
    tnx in advance..
     
  4. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Do you meant input only numbers ?

    If that is the case use getche function to write your own scanf function where if characters entered is anything apart from number you do not take that as input.
     
  5. LuciferiA

    LuciferiA New Member

    Joined:
    Sep 8, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Sorry Sir.. i can't understand your instruction.. Can you show me some little examples?
     
  6. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Try this
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
    	char c;
    	while(1)
    	{
    		c = getch();
    		if(c>=48 && c<=57)
    			printf("%c",c);
    	}
    	getch();
    }
    
     
  7. LuciferiA

    LuciferiA New Member

    Joined:
    Sep 8, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Excuse me sir, is this a C++ source code? :D
    And whats meant with 48 and 57 Sir?
     
  8. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Its a C code but it does not differ much apart from changing printf to cout and 48 and 57 are ASCII code of numbers.
     
  9. LuciferiA

    LuciferiA New Member

    Joined:
    Sep 8, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Awtz.. Ok sir tnx!
    Sir can you explain this condition if(c>=48 && c<=57)
     
  10. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    I can but would like to know what you understood by the condition
     
  11. LuciferiA

    LuciferiA New Member

    Joined:
    Sep 8, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    I know about conditional statements. But what i don't understand is the 48 and 57.
    Hope you understand my english. LoL hihihi
     
  12. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    It checks if the input character is between 0 and 9
     
  13. LuciferiA

    LuciferiA New Member

    Joined:
    Sep 8, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Ahh ok Sir.
    Sir can you give me some simple quiz about C++?
    So that i have some homework to do everynight?
     
  14. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Check out my other forum www.go4expert.com as it has some good interview questions on C++ for you to work on.
     
  15. LuciferiA

    LuciferiA New Member

    Joined:
    Sep 8, 2009
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    Ok sir tnx fOr d Link!
     

Share This Page