1

i'm new to C programing and i was testing some code when i compiled it this error came up:

fatal error: 'conio.h' file not found #include <conio.h>

 

this was on the top of the code i was testing:

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

i searched about this error but i only found answers related to windows and ubuntu

i'm running mac os

MakeTheErrorDie
  • 87
  • 1
  • 1
  • 10
  • 7
    The header conio.h is not a standard C header. Do not use it. – Vlad from Moscow Apr 29 '21 at 15:26
  • Looks like another dup of [this](https://stackoverflow.com/q/8792317/1707353). – Jeff Holt Apr 29 '21 at 15:39
  • Does this answer your question? [Where is the header file on Linux? Why can't I find ?](https://stackoverflow.com/questions/8792317/where-is-the-conio-h-header-file-on-linux-why-cant-i-find-conio-h) – Jeff Holt Apr 29 '21 at 15:40

5 Answers5

5

conio.h is not a standard library header, and the functions it declares are not standard library functions - it's specific to an ancient implementation that isn't used much anymore. If the code you're trying to build uses conio routines like getch(), then it won't build on a Mac.

John Bode
  • 119,563
  • 19
  • 122
  • 198
  • 2
    is there an alternative for mac, or is this program is entirely incompatible with Mac? – MakeTheErrorDie Apr 29 '21 at 15:59
  • @MakeTheErrorDie: There really isn't a `conio` equivalent for MacOS. As for whether the program is *entirely* incompatible, I can't say without seeing the code. On the implementation that provided it, it was common to launch programs from within the IDE - it would open a new terminal window in which the program would run. As soon as the program exited, the window would close. A lot of intro programs put `getch()` as the last statement so the program wouldn't exit until you pressed a key. – John Bode Apr 29 '21 at 18:48
  • @MakeTheErrorDie: It's possible that the only thing you need to do is remove the `#include ` and any `getch()` statements and your code will build and run correctly. It's also possible that it makes more use of `conio` than that - without seeing the code I can't really say. – John Bode Apr 29 '21 at 18:49
  • removing getch() and # include worked :) – MakeTheErrorDie Apr 30 '21 at 02:56
1

I encountered the same situation. My xcode suggested #include <curses.h> instead. I changed accordingly, now it builds.

Rocket
  • 21
  • 3
0

It depends of what compiler are you using. Conio.h is mostly header for MS-DOS compiler, so it can be unavailable in some others packages. If you tried to use getch() as tool to stop console from closing after execution, simply replace it with scanf():

int a;
scanf(%d,a);

Console will close after pressing Enter

Gihratic F
  • 11
  • 1
0

See here Conio is dead already do not use my friend I have noticed many YouTubers in initial coding use getch() to make your code wait for you to press a key and when pressed it is done but now conio isn't even a part of c/c++ it works in MS-DOS based compiler and turbo-c++ but most of the turbo c++ code turns out erroneous as they use old c/++ syntax that is deprecated a long back in the history of development in c/c++.

    #include <conio.h>

Suggestion : Remove These lines and voila it works Happy Coding!

0

"use this line in main function then we can use conio file int main(int argc, char const *argv[])"

amit
  • 1
  • How would this allow using a file that does not exist? – Gerhardh Apr 18 '23 at 07:05
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 19 '23 at 09:31