By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

i cannot use getch() function in linux , but i need to ask the user to press enter

P: 3
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void func(int);
  4. void main()
  5. {
  6. int x=1;
  7. func(x);
  8. printf("##############");
  9. }
  10. void func(int x)
  11. {
  12.     if(x!=0)
  13.     {
  14.     printf(" X!=0");
  15.     getch();
  16.     return;
  17.     }
  18. }
on compiling this code the error is

e2.c:2:18: error: conio.h: No such file or directory


and on commenting <conio.h> the error is ax follows

e2.c:2:18: error: conio.h: No such file or directory


wat 2 do ????
Dec 6 '10 #1
Share this Question
Share on Google+
3 Replies


Banfa
Expert Mod 5K+
P: 8,916
Don't use getch() to make your program pause at the end, it is unnecessary would be the best idea.

While you are about it main returns int not void. This might not have been a problem on Windows since MSVC supports main returning void as an extension but on Linux I imagine most of the compilers (gcc for instance) are more strict and you should return int to void undefined behaviour.

If you are going to write software for multiple platforms then get used to writing portable software and that means not relying on non-standard headers and libraries such as "conio.h".
Dec 6 '10 #2

P: 3
#include <curses.h> instead of <conio.h>
Dec 8 '10 #3

P: 9
Expand|Select|Wrap|Line Numbers
  1. #include <ncurses.h>
  2. int main()
  3. {
  4.   initscr();
  5.   cbreak();
  6.   printw("Press Any Key.. ");
  7.   getch();
  8.   endwin();
  9.   return 0;
  10. }
  11.  
- Make sure you have installed ncurses library before compiling.
- While compiling, pass a argument -lncurses to gcc



-RajX
Dec 9 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.