×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

Popular functions of conio.h header file in C language

conio.h is a header file, stands for "Console Input & Output". It contains the functions of console input and output.

Syntax to include:

#include <conio.h>

Popular functions of conio.h are,

Functions Description
clrscr() This function is used to clear the output screen.
getch() This function is used to get a single character from keyboard without echo.
textcolor() This function is used to define text color.
Color code should be between 0 to 15 (0x00 to 0x0F)
textbackground() This function is used to define background color of the text.
Color code should be between 0 to 15 (0x00 to 0x0F)

1) clrscr()

clrscr() is used to clear the output screen.

Syntax:

clrscr();

2) textcolor()

textcolor() is used to define the text color on the output screen. The defined color will be displayed by using the crpintf() function.

Syntax:

textcolor(int color-code);

color-code starts from 0x00 to 0x0f (Decimal Values : 0 to 15), you can also use the color name like RED, BLACK, WHITE, YELLOW, etc.

Consider the example,

#include <conio.h>

int main()
{
    int iLoop;
    
    clrscr();
    
    for (iLoop = 0; iLoop <= 15; iLoop++) {
        textcolor(iLoop);
        textbackground(15 - iLoop);
        cprintf("www.includehelp.com");
        cprintf("\r\n");
    }
    
    getch();
    
    return 0;
}

Output:

textcolor in conio.h - c programming tutorial

3) textbackground()

textbackground () is used to define the text background color on the output screen. The defined color will be displayed by using the crpintf() function.

Syntax:

textbackground (int color-code);

color-code starts from 0x00 to 0x0f (Decimal Values : 0 to 15), you can also use the color name like RED, BLACK, WHITE, YELLOW, etc.

Consider the example,

#include <conio.h>

int main()
{
    int iLoop;

    clrscr();

    for (iLoop = 0; iLoop <= 15; iLoop++) {
        textcolor(iLoop);
        textbackground(15 - iLoop);
        cprintf("www.includehelp.com");
        cprintf("\r\n");
    }

    getch();

    return 0;
}

Output:

textbackgroundcolor in conio.h - c programming tutorial

4) getch()

getch() is used to input a character from the console without echoing the character on the screen.

Syntax:

getch();



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.