Being an experience programmer (fortran and assembly), I decided to modernize my resume and tackle c. In the process, I learned that like other programming languages, there were many 'versions' of c.

Several course books I read use the conio.h header file. I was looking for a substitute for conio.h in linux. I did indeed find a thread labled "substitute for conio.h" in this forum, but it was mostly a hatefest about whether clrscr should be used or not, and didn't really seam to answer the original question:

When you run into conio.h in a given program, and want to substitute it, so you can move on with learning code, you can't just plug and play - and there are MANY basic functions of C taught that use the conio.h (console input-output header), none of which were discussed in the forum.

Could someone with more experience in Linux C please clarify how to substitute the following commands (what header file needs to be used for each?) for the beginners trying to learn how to program in C with a Linux machine, but obviously using the wrong book. (and it might not be a bad thing to point to a proper book on programming in C specifically written for the Linux language).

The following are a list of functions in the conio.h header - there may be more, feel free to embellish.

cgets - reads a string directly from the console
clrscr- clears the screen
cprintf - Formats values and writes them directly to the console.
cputs - writes a string directly to the console
cscanf - reads formatted values directly from the console
getch - reads a character from the console (without buffering or echo)
getche - reads a character frm the console (without buffer but with echo)
kbhit - determines if a keyboard key was pressed
putch - writes a character directly to the console
ungetch - puts a character into the keyboard buffer

Recommended Answers

All 6 Replies

There is no *nix version of conio.h. But I think you could accomplish the same if you used curses or ncurses library, or more low level yet if you use termcap library. Here is a related link on Fedora.com

I would recommend you stay away from all practices/function/headers that are compiler/OS dependent. Unlearn conio.h since only 1% of the compilers ever made have it defined. And of those compilers, each conio.h is different.

As someone who knows very little of conio.h, could you explain how cprintf, cscanf, cgets, cputs etc. behave differently than the standard functions of the same name minus the "c" at the beginning?

Code these functions on your own. It would be quite nice programming practice.

As someone who knows very little of conio.h,...

Please reread my post.

But if you insist on knowing worthless programming trivia, here's a start

As someone who knows very little of conio.h, could you explain how cprintf, cscanf, cgets, cputs etc. behave differently than the standard functions of the same name minus the "c" at the beginning?

They were written by Borland Turbo C compiler for MS-DOS Version 6.X or earlier and used DOS interrupts that read/write directly to/from keyboard and screen memory. The only really useful function in it was kbhit() which allows you to check the keyboard memory to see if there is anything in it. Standard C functions don't have anything similar.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.