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
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.
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
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!
I encountered the same situation. My xcode suggested #include <curses.h> instead. I changed accordingly, now it builds.
Related
I'm working on an assignment and I'm pretty much done, but I've run into a roadblock. I'm trying to print out all the "emirp" numbers my program generates, but if I try to print after running my EMIRP finding loop, it causes a Debug Assertion Failed error with this message.
Here's the program source.
http://pastebin.com/f81rE4hb
I'm a C++ guy in transition to using C, so maybe it's a C-specific problem causing it. If you need an explanation of anything, just ask. I'm compiling this with Microsoft Visual Studio 2012 Professional.
In my case it had to do with mixing unicode main program with non unicode external library written in C. This is what helped to me. Before calling first printf in external library I had to change console mode to ansi. After external library call I had to set mode back to unicode:
#include <io.h>
#include <fcntl.h>
_setmode(_fileno(stdout), _O_TEXT);
....
_setmode(_fileno(stdout), _O_U16TEXT);
Your problem is that you do emirps++:
You won't be able to free the memory that you've initially allocated, since emirps no longer points to the beginning of that memory.
You most certainly can't go about passing emirps[i] to printf (or any other function for that matter) at that point.
BTW, just noticed that there's a "whole bunch of mallocs" in your code not being freed anywhere...
How do I go about finding the source code behind standard C functions (under Linux/Ubuntu 13)?
Case in point, chdir(). I know I have to #include <unistd.h> but then I encounter a bug, and I suppose the source code would help me figure out this bug.
Thanks if you point me out to the correct source - but real thanks if you give me a method for finding the correct source file every time I need one.
The project is online at GNU C Library.
Yes, the source code to the GNU libc is available at https://sourceware.org/git/?p=glibc.git;a=tree
I was given the source code to modify an MS-DOS program built back in 1992. I have the EXE file and it runs fine, but I need to modify the source code. The source code needs the below headers to compile.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <dos.h>
#include <dir.h>
#include <alloc.h>
#include <ctype.h>
#include <string.h>
#include <mem.h>
#include <values.h>
Does anyone know what was used and are there any modern compilers that can handle this? I tried with Visual Studio 2010 and GCC "out of the box", but it fails because some headers are missing (dir.h, alloc.h, mem.h, values.h)
It might be more interesting to ask what what function declarations, type declarations, global variable declarations and macros it needs to have. The particular arrangement of those things into headers isn't very interesting as long as they are all there.
So comment out the offending #includes and let the compiler complain about the bits it is missing. Then you know what you're looking for.
You could try the Open Watcom compiler, which is one of the few relatively up-to-date compilers that builds 16-bit DOS executables. Other than finding an old MS or Borland compiler (or whatever was originally used), that's probably the easiest route.
If you want to rebuild for a different platform instead of rebuilding for DOS again, you'll likely have to make a lot of changes to the program itself. That may be worthwhile, but may be a lot of work and have a lot of surprise headaches.
There's Turbo C++ 1.01, not so modern, though, that appears to have all these header files as well. I still occasionally use it.
You might try using DJGPP. According to the documentation, it may have the headers you need.
a) Remove all the header files
b) Try a compile
c) Look up which header file the undefined function/type is int
d) Add the header file
e) repeat
In my Turbo C++ program, I can't run any of the graphics program. When it compiles, it shows an error like:
undefined symbol _line, _closegraph,_ getmaxx etc...
Is it due to the settings of my c-program?
Is this an old program that was written for Turbo C++, and that you're trying to compile with a modern compiler? If so, it might be the case that the program uses compiler-specific extensions and libraries, that are simply not available in the compiler you're using now.
If that is the case, you must either
find an existing library for your current environment that emulates the old Turbo C++ one, or
find out exactly what each call is supposed to do, and change the code to use something that your environment supports.
It's compile error and not link error. Looks like "graphics.h" is missing.
Do
#include "graphics.h"
Those errors are typical of a missing library in your build. Try linking the appropriate libraries and rebuild the solution (most likely graphics.lib).
-John
If the problem is of compiling error then you may add the header file:
#include<graphics.h>
if the problem still persists then make sure you have added the header file:
#include<dos.h>
I am using getch() and my app crashes instantly. Including when doing:
int main()
{
getch();
}
I can't find the link but supposedly the problem is that it needs to turn off buffering or something strange along those lines, and I still want cout to work along with cross platform code.
I was told to use std::cin.get(), but I'd like the app to quit when a key is pressed, not when the user typed in a letter or number then press enter to quit.
Is there any function for this? The code must work under Mac (my os) and Windows.
Linking/compiling is not an issue; I include <curses.h> and link with -lcurses in XCode, while Windows uses <conio.h>.
Have you looked in <curses.h> to see what the getch() function does?
Hint: OSX and Linux are not the same as Windows.
Specifically, as a macro in <curses.h>, we find:
#define getch() wgetch(stdscr)
Now, there appears, on your system, to be an actual function getch() in the curses library, but it expects stdscr to be set up, and that is done by the curses initialization functions (initscr() and relatives), and that is signally not done by your code. So, your code is invoking undefined behaviour by calling curses routines before the correct initialization is done, leading to the crash.
(Good hint from dmckee - it helped get the link line out of acidzombie24, which was important.)
To get to a point where a single key-stroke can be read and the program terminated cleanly, you have to do a good deal of work on Unix (OSX, Linux). You would have to trap the initial state of the terminal, arrange for an atexit() function - or some similar mechanism - to restore the state of the terminal, change the terminal from cooked mode into raw mode, then invoke a function to read a character (possibly just read(0, &c, 1)), and do your exit. There might be other ways to do it - but it certainly will involve some setup and teardown operations.
One book that might help is Advanced Unix Programming, 2nd Edn by Mark Rochkind; it covers terminal handling at the level needed. Alternatively, you can use <curses.h> properly - that will be simpler than a roll-your-own solution, and probably more reliable.
You have not exhibited a
#include <stdio.h>
or
#include <curses.h>
or similar line. Are you sure that you are linking against a library that includes getch()?
Use the cin.get() function for example:
#include <iostream>
using namespace std;
int main()
{
char input = cin.get();
cout << "You Pressed: " << input;
}
The program would then wait for you to press a key.
Once you have, the key you pressed would be printed to the screen.
The getch function is not available on Unix-like systems, but you can replace it with console commands through your compiler with the system function.
Usage:
In Windows you can use system("pause");
In Unix-like systems (such as OSX) you can use system("read -n1 -p ' ' key");
Note: system is declared in <stdlib.h>.