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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.