Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

Conio.h in C

Last Updated on June 20, 2023 by Mayank Dham

When it comes to developing interactive console applications in C, developers often find themselves craving more control and versatility. This is where Conio.h steps in as a valuable tool that unleashes a world of possibilities. Conio.h, short for console input/output, is a powerful C library that provides enhanced functionalities for console interactions.

Developed to supplement the standard C libraries, Conio.h offers an array of functions specifically designed to manipulate the console environment. From managing input and output to controlling cursor movements, Conio.h empowers programmers to create dynamic, user-friendly console applications.

In this article, we will delve into the intricacies of Conio.h and explore its various features, demonstrating how it can elevate your C programming experience. We will discuss the history and purpose of Conio.h, examine its core functions, and showcase practical examples of its implementation.

Introduction to Conio.h

conio.h full form stands for “Console Input & Output”. conio.h in C programming is a header file that provides the function of console input and output. GCC compiler doesn’t support conio.h file, as we studied that it provides console input/output functions. So we will discuss some important functions that are used to clear the screen, hold the screen, and change the background color of the text.

Syntax to include

#include 

Note: Conio.h, which is given by the Borland Turbo C compiler, is not supported by the GCC compiler.

C < conio.h> Library Function

Some important function of < conio.h> library function:

Some additional functions provided by the Conio.h header file include highvideo(), movetext(), gotoxy(), wherex(), and wherey(). These functions offer further flexibility and control over console interactions in C programming.

The highvideo() function allows you to brighten a character string and display it on the screen, adding visual emphasis to specific text elements within your console application.

With the movetext() function, you can dynamically move text on the screen, providing a means to create engaging visual effects or adjust the positioning of important information within your program’s interface.

The gotoxy() function accepts two arguments, representing the x and y coordinates, respectively, and allows you to position the cursor at a specific location on the console screen. This feature is particularly useful when you need precise control over the cursor’s placement for input or output purposes.

In addition, the wherex() and wherey() functions enable you to retrieve the current x and y coordinates of the cursor, providing valuable information about the cursor’s position on the console screen.

By incorporating these functions into your C programs, you can further enhance the interactivity and visual appeal of your console applications, resulting in a more engaging user experience.

clrscr()

The clrscr() function is used to clear the console screen, effectively erasing any text or graphics that were previously displayed.

When invoked, clrscr() clears the entire console window, making it blank and ready for new content to be displayed. This function is especially useful in scenarios where you want to refresh the console screen and remove any existing output before presenting new information to the user.

The clrscr() function simplifies the process of clearing the console screen, allowing you to maintain a clean and organized user interface for your console-based applications.

Code:

#include <stdio.h>
#include <conio.h>


int main()
{

   printf(“Welcome”);
  printf(“\nScreen before use of clrscr”);
  clrscr();
  printf(“Screen After use of clrscr() function”);
  return 0;


}

Output:

Screen After use of clrscr() function

Explanation:
In the above c program we use < conio.h> header file function which is clrscr() , this function clears the screen, we observe on the output screen that the print statement
Before clrscr function has been clear. and print statement after clrscr function is coming on the output screen, This shows the clrscr () function of < conio.h> header file clear the output screen.

getch()

This < conio.h> header file function is used to hold the screen,here we want the window to wait for user input before terminating or continuing the program.

Code:

#include <stdio.h>
#include <conio.h>

int  main()
{

      printf(“Input the value”);
      

    getch():
    return 0;

}

Output

Input the value:

Explanation
In the above c program we use < conio.h> header file function which is getch(), this function here holds the screen, like if we observe that after print statement (“Input the value”), it prints on the output screen and getch() holds the screen,and if press any key then only the screen get a release or terminate.

getche()

This < conio.h> header file function is used to accept the alphanumeric values and simultaneously prints the character on the screen which is given as the input that
Echoes the character, it is similar to getch() function.

Code:

#include<stdio.h>
#include <conio.h>

int  main()
{

       printf(“Input the values”);
       getche();
        return 0;


}

Output

Input the value:

Explanation
In the above c program we use < conio.h> header file function getche(), which is similar to the getch() function but it also accepts the alphanumeric value and simultaneously prints on the console /output screen. so it holds and also prints on the screen before releasing the screen that is why it similar to the getch function because here also screen hold/wait happens.

putch()

This < conio.h> header file function is used to print or put a character on the screen/console.

Code:

#include<stdio.h>
#include <conio.h>

int  main()
{

         char  k=’l’;
       putch(k);
     
        return 0;


}

Output

l

Explanation
In the above c program we use < conio.h> header file for putch() function, basically, this function is used to print or put characters on the console, here we observe we have taken the char variable name as k, which is equal to ‘l’ after this we use putch function and pass the k variable. we observe on the output screen that character ‘l’ has been printed.

cgets()

This < conio.h> header file function is used to input a group of characters (string) from the console until it gets carriage return and linefeed.

Code:

#include <stdio.h>
#include <conio.h>

int  main()
{
    char  s[100];
   char  *str;
    S[0] =50;
   printf(“Input  the character:”);
   Str =cgets(s)
   printf(“\nOutput on the screen:%s”, str);
   return 0;


}

Output

Input the character:    welcome to college dekho
Output on the screen:   welcome to college dekho

Explanation
The two header files stdio.h and conio.h have been included in the code above, and we’ve created a variable of size 100 called s and an str variable to hold the input value before printing it. After that, we use cgets() to enter a string, store it in a variable called s, and then output the value in the final statement

cputs()

This < conio.h> header file function is used to print the string (group of characters) on the console or output screen.

Code:

#include <stdio.h>
#include <conio.h>

int  main()
{
   cputs (“Welcome Prepbyes”)
   

   return  0;



}

Output

Welcome Prepbytes

Explanation
In the provided C program, the header file is used to access the cputs() function, which is used for printing a whole string on the console. In this program, the string ‘WelcomePrepbytes’ is printed using the cputs() function. Upon execution, it is observed that the string ‘Welcome Prepbytes’ is printed on the output screen.

textcolor()

This < conio.h> header file function is used to define text color.

textbackground()

This < conio.h> header file function is used to

Conclusion
In conclusion, the header file is not a part of the standard C library and is typically found in older versions of C compilers, such as Borland’s Turbo C/C++. It provides a set of functions for console-based input and output operations, such as reading and writing characters, clearing the screen, and controlling cursor movement. However, it is important to note that the header file is not standardized and may not be available in all C compilers or platforms.

Frequently Asked Questions (FAQ) about in C:

Q1. What is ?

is a header file in C programming that provides functions for console-based input and output operations.

**Q2. What functions are available in ?**
Common functions available in include getch(), getche(), putch(), cputs(), clrscr(), and functions for controlling cursor movement.

**Q3. Is a standard header file?**
No, is not a part of the standard C library. It is specific to certain compilers, particularly older versions like Borland’s Turbo C/C++.

**Q4. Can be used in all C compilers?**
No, may not be available in all C compilers or platforms. It is recommended to use standard library functions for console-based operations to ensure portability.

**Q5. What are some alternatives to ?**
Portable alternatives for console-based operations include standard library functions like stdio.h for input/output and ncurses library for advanced console manipulation.

**Q6. Why is commonly used?**
was popularly used in older C compilers as it provided convenient functions for console-based operations. However, with modern compilers, alternative approaches are recommended for improved portability and compatibility.

Leave a Reply

Your email address will not be published. Required fields are marked *