0
#include "stdio.h"
#include "conio.h" 
#include "stdlib.h"

#define RANGE(i, min, max) (i<min) || (i>max) ? 1: 0

int main (void )
{
    int r;
    do
    {
        do{
            r=rand();
        } while (RANGE(r, 1, 100));
        printf("%d", r);
    }
    while (!kbhit());
    return 0;
}

When I run this programme I find the following error:

conio.h: No such file or directory

If delete #include "conio.h" then I find the following error:

Undefined symbols for architecture x86_64:
"_kbhit", referenced from:
_main in cckd1NC4.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

How can I solve this problem? What are reason behind these? Would you please tell me?

DIF
  • 2,470
  • 6
  • 35
  • 49
Kabir
  • 43
  • 2
  • 2
  • 4

3 Answers3

3

the double quotes in #include "something.h" means the file something.h is present in the current directory ie where the source file is located. Where as the <> symbols in #include <something.h> means that something.h is present in the standarad library folder ie for example the /usr/include folder. conio.h is a part of the standarad library so you need to use the <> symbols instead of the double quotes. The error you are seeing is because the linker is not able to find the function definition of kbhit() to link with your code to make the binary/executable.

snibu
  • 581
  • 4
  • 16
  • # include #include #include I have used this but not work. I did not supply any header file. But I does not work. I am running in Mac OS X. – Kabir Mar 05 '12 at 15:14
  • you should check your environment (C_INCLUDE path) or your -I parameters to the compiler – Peter Miehle Mar 05 '12 at 15:16
  • How do u compile?...Which compiler u use? Can you paste the command you use for compiling...As Peter said, you can use the -I parameter in gcc for specifying the include path – snibu Mar 05 '12 at 15:21
  • Actually, while double quotes are **poor form** here, they will work. `#include "foo"` searches the current directory first, then the system directories. `#include ` searches **only** the system directories. – Edward Thomson Mar 05 '12 at 23:38
  • (Or, at least they would work if `conio.h` existed anywhere anymore.) – Edward Thomson Mar 05 '12 at 23:38
3

conio.h is an old DOS header, almost never used anymore. The same functionality is now in curses.h. Make sure that curses (or ncurses) is installed on your machine, and try

#include <stdio.h> 
#include <stdlib.h>   
#include <curses.h> 

For what it's worth, RANGE is defined with far too few parenthases;

#define RANGE(i, min, max) (i<min) || (i>max) ? 1: 0

Would have problems with something like

 if(!RANGE(i, 100 200))

Which would become (parens added for clarity)

(!(i<100)) || (i>200)

Which isn't what you want. Define it instead as

#define RANGE(i, min, max) (((i)<(min)) || ((i)>(max)))

And, read up on Macro Pitfalls.

Dave
  • 10,964
  • 3
  • 32
  • 54
2

in C #include <lib.h> is different to #include "lib.h". The first searches for the header files in the systems include path, and the second in the files include path

Peter Miehle
  • 5,984
  • 2
  • 38
  • 55