"Z Code Writer" is an Online Blog for Programmer & Beginner. Here, You will Find tech, Build your Programming Skills and other Programming Language Like C, C++, HTML, Java Script Java Code, Web Designing and University Of Sialkot (USKT) CGPA / GPA Calculator etc.

Sunday, 21 July 2019

Character Input

Character Input

      The process to enter characters into computer is called character input. The scanf() function can be used for character input. However, C language provides functions that are specially used for characters input. The important character input functions are getch() and getche(). Both these functions are defined in header file "conio.h".


The getch() Function


      The word getch stands for get character. This function is used to get (input) a single character from keyboard during execution of program. The entered character is not displaying on the screen. Similarly, the input process is automatically completed without pressing the Enter key. This function is normally used to pause the execution of program.
      The general syntax to call this function is as follows:
                   [ var  = ]  getch ( ) ;
      The 'var' is of 'int' type. The ASCII value of entered character is stored into it. The use of [var =] is optional.


The getche() Function


      The word getche stands for get character echo. The word echo means repeat or display. This function is similar to getch() function. It is also used to get (input) a single character from keyboard during execution of program. However, the entered character is displayed on the screen.
      The general syntax to call this function is as follows:
                   [ var  = ]  getche ( ) ;
      The 'var' is of 'int' type. The ASCII value of entered character is stored into it. The use of [var =] is optional.


The gotoxy() Function


      This function is used to position the screen cursor on the specified location on the screen. Usually, gotoxy() function is used when an output is to be displayed on a specified location on the screen. This function is also defined in "conio.h" header file.
      The general syntax to call gotoxy() function is as follows:
                    gotoxy ( x,  y ) ;

Where

x                  It indicates the x-coordinate or column number on the screen. Its value can be from 0 to                      79.
y                  It indicates the y-coordinate or row number on the screen. Its value can be from 0 to 24                        or 39.
      
      For example, to display "Welcome" on the screen starting from row 16 and column 5, the statements are;
                    gotoxy ( 4,  15 ) ;
                    printf ( "Welcome" ) ;


The gets() Function


      The word "gets" stands for get string. This function is specially used to input (or get) data into a string variable from the keyboard during program execution.
      Any type of characters, including spaces and special characters can be entered using this function. Enter key is pressed to complete the input process. When Enter key is pressed, a null character ('\0') is automatically added at the end of the string variable.
      The general syntax to call this function is as follows:
                    gets ( strvar ) ;

Where

strvar           It represents the string variable into which data is to be stored.


Difference Between scanf() Function and gets() Function


      Data can also be entered into a string variable using scanf() function. But space character cannot be inserted into the string variable using this function. When a space key is pressed during input process, this function is immediately appends the null character ('\0') at that place in the string variable. The characters entered after the space are not stored in the string variable. Therefore, gets() function is specially used to get data into string variable.


The puts() Function


      The word "puts" stands for put string. This function is used to display the string on the computer screen. The new line is automatically inserted after displaying the string.
The general syntax to call this function is as follows:
                        puts ( string ) ;

Where

string              It represent the string to be displayed on the screen. It can be a string variable or string constant. In case of string constant, the string is enclosed in double quotation marks.
      For example, to display "Welcome" on screen, the statement is written as;
                        puts ( "Welcome" ) ;
It is equivalent to:
                        printf ( "Welcome\n" ) ;


No comments:

Post a Comment

Thanks For Visiting Here...!! I will Reply you as soon as possible.