Non-Standard I/O Functions in C
Last Updated :
11 Jun, 2025
While the C standard library provides robust functions for input/output operations, many C implementations include non-standard I/O functions that offer additional functionality or convenience that are not covered by the ANSI C specification.
The non-standard functions may not come bundled with every C compiler. We may need to install the relevant library manually to use them. Following are some commonly used non-standard Input and Output function in C:
1. getch() and getche()
These functions are the part of conio.h library for windows. They are used to read a single character from the keyboard without waiting for a newline.
Syntax
C
ch = getch();
ch = getche();
This function does not take any parameters. It returns the ASCII value of the pressed key (as an int). The getch() function does not echo the character to the console, while getche() does.
Example
C
#include <conio.h>
#include <stdio.h>
int main() {
printf("Press a key (not echoed): ");
int ch = getch();
printf("\nYou pressed: %c\n", ch);
printf("Press a key (echoed): ");
ch = getche();
printf("\nYou pressed: %c\n", ch);
return 0;
}
Output
Press a key (not echoed): pressed E
You pressed: E
Press a key (echoed): pressed E
E
You pressed:E
2. kbhit
The kbhit() function checks if a key has been pressed without blocking. It is also the part of conio.h header file.
Syntax
C
This function does not take any parameter and return a non-zero if a key is available, zero otherwise.
Example
C
#include <conio.h>
#include <stdio.h>
int main() {
printf("Press any key to continue, or wait...\n");
while (!kbhit()) {
printf("Waiting...\n");
// Non-standard sleep, discussed later
sleep(1);
}
printf("Key pressed: %c\n", getch());
return 0;
}
Output
Press any key to continue, or wait...
Waiting...
Waiting...
Key pressed: f
3. clrscr()
Also the part of conio.h library, this function is used to clear the console screen. It is exclusive to windows systems.
Syntax
C
This function neither take any parameter nor returns any value.
Example
C
#include <conio.h>
#include <stdio.h>
int main() {
printf("Screen will clear in 2 seconds...\n");
sleep(2);
clrscr();
printf("Screen cleared!\n");
return 0;
}
Output (Before clrscr())
Screen will clear in 2 seconds...
Output (After 2 seconds)
Screen Cleared
4. gets_s()
The gets_s() is a safer alternative to the deprecated gets, reading a line into a buffer with a size limit. It is optional and is defined inside stdio.h header file if defined.
Syntax
C
where,
- buff: string buffer where input is stored.
- size: Number of characters to read.
Example
C
#include <stdio.h>
int main() {
char str[20];
if (gets_s(str, sizeof(str)) != NULL) {
printf("Read: %s\n", str);
} else {
printf("Input error\n");
}
return 0;
}
Output
This is input string for testing
Read: This is input string
Similar Reads
Function Pointer in C In C, a function pointer is a type of pointer that stores the address of a function, allowing functions to be passed as arguments and invoked dynamically. It is useful in techniques such as callback functions, event-driven programs, and polymorphism (a concept where a function or operator behaves di
6 min read
main Function in C The main function is the entry point of a C program. It is a user-defined function where the execution of a program starts. Every C program must contain, and its return value typically indicates the success or failure of the program. In this article, we will learn more about the main function in C.E
5 min read
Passing Pointers to Functions in C Prerequisites: Pointers in CFunctions in C Passing the pointers to the function means the memory location of the variables is passed to the parameters in the function, and then the operations are performed. The function definition accepts these addresses using pointers, addresses are stored using po
2 min read
C String Functions C language provides various built-in functions that can be used for various operations and manipulations on strings. These string functions make it easier to perform tasks such as string copy, concatenation, comparison, length, etc. The <string.h> header file contains these string functions.Th
6 min read
Types of User Defined Functions in C A user-defined function is one that is defined by the user when writing any program, as we do not have library functions that have predefined definitions. To meet the specific requirements of the user, the user has to develop his or her own functions. Such functions must be defined properly by the u
4 min read
tmpfile() function in C In C Programming Language, the tmpfile() function is used to produce/create a temporary file. tmpfile() function is defined in the "stdio.h" header file. The created temporary file will automatically be deleted after the termination of program. It opens file in binary update mode i.e., wb+ mode. The
1 min read
Opening Modes in Standard I/O in C/C++ with Examples Pre-requisites: File Handling in C++ So far the operations using the C program are done on a prompt/terminal that is not stored anywhere. But in the software industry, most of the programs are written to store the information fetched from the program. One such way is to store the fetched information
13 min read
User-Defined Function in C A user-defined function is a type of function in C language that is defined by the user himself to perform some specific task. It provides code reusability and modularity to our program. User-defined functions are different from built-in functions as their working is specified by the user and no hea
6 min read
ANSI C - C89 Standard The C programming language, developed in the early 1970s by Dennis Ritchie at Bell Labs, quickly gained popularity due to its efficiency, portability, and flexibility. However, C variations and extensions by different compiler vendors led to compatibility issues. To address this, the American Nation
5 min read
Non-blocking I/O with pipes in C Prerequisite: pipe() System callWhen I/O block in pipe() happens? Consider two processes, one process that's gathering data(read data) in real time and another process that's plotting it(write data). The two processes are connected by a pipe, with the data acquisition process feeding the data plotti
6 min read