checking the input is character or not

This is a discussion on checking the input is character or not within the C++ Programming forums, part of the General Programming Boards category; 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; ...

  1. #1
    sal
    sal is offline
    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
    sal
    sal is offline
    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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,171
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

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, 04:42 AM
  2. Checking value of one character in array
    By System_159 in forum C Programming
    Replies: 7
    Last Post: 01-17-2008, 04: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, 08: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


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