Connect to

facebook google Email you tube you tube you tube
Theme images by MichaelJay. Powered by Blogger.

Projects

2.6.17

How to input characters without hitting Enter Key in C and C++

Well this is one feature which many of us want to include in our C++ projects.

Firstly what does this statement mean?
When we start learning C/'C++, to input we always use functions like scanf in C and cin in C++. But have you ever tried inputting characters using getch() or getche()?



Before starting What is the getch() function?

Getch() is a nonstandard function and is present in conio.h header file which is mostly used by MS-DOS compilers like Turbo C. It is not part of the C standard library or ISO C, nor is it defined by POSIX (Source: http://en.wikipedia.org/wiki/Conio.h)
It reads also a single character from keyboard. But it does not use any buffer, so the entered character is immediately returned without waiting for the enter key.


Let us see a Program : 


C++ :

#include
#include

 void main()
  { char c;
      c=getch();
      cout<<'\n'<
     getch();
}

C: 

#include
#include

 void main()
  { char c;
      c=getch();
     printf("\n%c",c);
     getch();
}



No comments:
Write comments

Interested in our works and services?
Get more of our update !