Thread: checking the input is character or not

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    9

    checking the input is character or not

    Code:
    #include<iostream.h>
    #include<conio.h>
    int main(){
    clrscr();
    int i; char * c;
    cin>>c;
    i=*c;
    if(i<48 || i>57)return 0;
    else cout<<i<<" "<<c; getch(); return 0;}

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    9
    the PROBLEM IS THAT ONCE THE PROGRAM IS DONE... IT DOES NOT RETURN BACK TO CODING SCREEN

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I see a multitude of problems. I suggest that you:
    • Upgrade your compiler.
    • Get rid of non-standard clrscr (see faq for alternatives).
    • Reading into a pointer that is non-initialized is undefined behavior. Read into an int or a char.
    • Don't use an if statement to check if it's a char; use std::isdigit to check if it's a digit (if it's not, it's likely a char).
    • Get rid of getch. See SourceForge.net: Pause console - cpwiki for alternatives on pausing the console.
    • Change iostream.h to iostream.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking if a character is a '\'
    By serg_yegi in forum C Programming
    Replies: 18
    Last Post: 03-04-2010, 05:42 AM
  2. Checking value of one character in array
    By System_159 in forum C Programming
    Replies: 7
    Last Post: 01-17-2008, 05:05 PM
  3. Checking to see if a string is just a newline character
    By Beowolf in forum C++ Programming
    Replies: 3
    Last Post: 11-14-2007, 09:29 PM
  4. Help with Input Checking
    By Derek in forum C Programming
    Replies: 7
    Last Post: 06-17-2003, 03:07 AM
  5. Checking validity of input character
    By yank in forum C Programming
    Replies: 8
    Last Post: 04-16-2003, 02:42 AM

Tags for this Thread