![Akhil Vijay](https://www.crazyengineers.com/img/avatar.jpg)
Member • Sep 9, 2015
Difference between stdio.h and conio.h
stdio.h
stdio.h stands for standard input-output header in C programming. This header file contains definitions for functions like printf(), scanf(), getchar(), putchar(), etc., which are standard input/output library functions in C.
Here is an example of stdio.h usage:
#include
int main() { int number; printf("Enter a number: "); scanf("%d", &number); printf("You entered: %d", number); return 0; }
In the above code, stdio.h is included at the top which allows the use of printf() for output and scanf() for input.
conio.h
conio.h stands for console input-output. This header file is specific to the DOS operating system and contains functions for console input/output operations. It's not part of the C standard library, so its use is generally discouraged due to its non-portable nature. It includes functions like getch(), clrscr(), kbhit(), etc.
Here is an example of conio.h usage:
#include
int main() { char ch; printf("Press a key to continue..."); ch = getch(); // Waits for a key press return 0; }
In the above code, getch() is a function from conio.h which waits for the user to press a key.
Differences between stdio.h and conio.h
- stdio.h is a standard C library for input/output operations while conio.h is specific to DOS and is used for console I/O operations.
- stdio.h is portable across different platforms whereas conio.h is not portable and mostly not present in modern compilers like GCC.
- The stdio.h library provides functions like printf(), scanf(), fopen(), fclose(), etc. which are universally recognized, while conio.h provides functions like clrscr(), getch(), kbhit(), which are not universally recognized.
- conio.h has functions that can be used for changing text color, moving the cursor, etc. These functionalities are not provided by stdio.h.
- Functions provided by conio.h are generally faster than stdio.h because they don't perform buffering of input/output operations.
It's important to note that because conio.h is not part of the standard C library, using it can lead to code that only works on certain systems or compilers. For this reason, many programmers avoid using conio.h and stick to the standard C library functions for input/output.