LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   New to Programming (https://www.linuxquestions.org/questions/programming-9/new-to-programming-33446/)

acascianelli 10-22-2002 10:54 AM

New to Programming
 
Im new to programming and linux. i'm running redhat 8.0 i have a simple intro to c class and i want to be able to make my programs under linux. i thougth this would be very easy with gcc and all but when i make a program in vi or any editor then try to compile it with gcc i get errors.

this is the program

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

void main(void)
{
printf("asdf");
getch();
}

as you can see this is a very simple program. when i use gcc to compile it cannot find conio.h . after a while i gave up on using command prompt to do this so i installed anjuta. but when i use anjuta to compile the same program i managed to add the directory that has conio.h so it can do a compile and a compile with make successfully, but when i go to do a build i get

/usr/bin/ld: cannot find -lconsole
collect2: ld returned 1 exit status

i am not logged in as root, any help would be greatly appreciated.

acascianellI@hotmail.com

Hko 10-22-2002 11:32 AM

The "conio.h" header file is (normally) not found on UNIX (-like) operating systems. If I recall correctly, it even is specific to Borland / Inprise ("turbo") compilers. So I'm quite surprised you did find it on your Linux-system.

If you want functionality similar to "conio.h" in Linux you'll need to learn about "ncurses". Which is quite different, more complex, and capable of more things than the conio-library.

However, the good news is, that you do not need the "#include <conio.h>" line at all in you program!

Just delete the "#include <conio.h>" line and also change "getch" to "getchar". Then compile again (with: "gcc -o myprog myprog.c" on the shell prompt).

theheapWalker 12-20-2017 12:29 PM

where is there a list of functions and header files we could expect gcc to come with?

astrogeek 12-20-2017 01:03 PM

@theheapWalker:

You have exhibited a pattern of seeking out old posts and replying to them without providing any useful information or questions of your own.

If you have questions of your own please post them to your own thread with proper context. Please see the Site FAQ for guidance in participation on this forum.

If this pattern continues your posting privileges may be suspended.

rhubarbdog 12-24-2017 10:21 AM

conio.h is a microsoft required header. You may have need for function kbhit(). I have code to replace this send me a message or reply to this if you find you need kbhit

rhubarbdog 12-24-2017 10:54 AM

The difference between getch and getchar is getch waits for any character and then continues, where as getchar will wait for either EOF or enter being pressed as it reads blocks of text. Read about the linux terminal and buffering


All times are GMT -5. The time now is 11:31 PM.