6

I have a C program which contains #include <dos.h> header. It shows a compile time error. I know that the dos.h header file is not valid in Linux.

Is there any other equivalent header for dos.h in Linux?

Jens
  • 69,818
  • 15
  • 125
  • 179
TamiL
  • 2,706
  • 4
  • 24
  • 44
  • As the name suggests, it is the *DOS* header file, therefore unavailable on Linux. What functionality do you need from `dos.h`? –  Jul 27 '12 at 04:43
  • 1
    For time functions you can refer this link : http://stackoverflow.com/questions/1442116/how-to-get-date-and-time-value-in-c-program – McLosys Creative Jul 27 '12 at 04:57
  • 3
    I had a good chuckle reading this question. If you want to get the time, try `man 2 time` or `man gettimeofday`. – asveikau Jul 27 '12 at 05:20
  • 6
    I did answer to the question, but I am surprised it is getting such a positive score. In my view, it is a vague question (not well formulated) and the poster could have googled it easily, and don't show any relevant source code, so the question is not a good question on SO. – Basile Starynkevitch Jul 27 '12 at 07:20

3 Answers3

10

dos.h header file is interface to the DOS operating system. They are not portable to operating systems other than DOS (means not works in Linux). Which functionality in dos.h you are going to use?

McLosys Creative
  • 759
  • 4
  • 9
  • 19
10

Linux is a Posix/Unix like system, so you should learn the system calls and facilities that you can use. Read the advanced unix programming book (or some equivalent; AUP is considered a very good book). You can also read advanced linux programming (even online, a copy is here). So Linux don't have a dos.h header.

You could also type man 2 intro to get an intro to syscalls, and their list in in syscalls(2) man page. From an application's point of view syscalls are elementary operations provided by the Linux kernel.

The GNU libc provides a big lot of functionality (e.g. standard C functions like malloc and fprintf, and system functions like fgetpwent to query user database, etc etc...) above the system calls. Almost every Linux program uses it.

If you care about coding stuff which should be portably runnable (after recompilation) on other similar systems (e.g. MacOSX or FreeBSD) consider following the Posix standard.

If you want to code a terminal screen application, consider using ncurses.

If you care about graphical interfaces, use a graphical toolkit like Qt or Gtk; they usually interact with an X11 server (and both Qt and Gtk are able to run on some other non Posix systems, e.g. Windows, by providing a common graphical abstraction layer.). Both Gtk and Qt are adding an abstraction layer (Glib and QCore respectively) above system functions and facilities (in particular above the pthreads standard thread library).

At last, Linux is free software; so you might find interesting to look inside the source code (of a library or utility) that you are using. You could even improve it and contribute to it.

In all these aspects, Linux programming is very different from Windows or DOS.

Don't try to mimic every Windows or Dos function into Linux (e.g. don't ask the equivalent of every dos.h function); learn the Posix/Unix way of thinking and coding.

The time(7) man page tells you a lot about time (various meanings and functions about it) on Linux.

Don't forget to ask warnings from the compiler with gcc -Wall -Wextra; as a general rule, improve your source code till you get no warnings.

There cannot be an exact Linux equivalent of dos.h because Linux (i.e. Unix or Posix spec) and Windows are systems with different features and concepts. However several free libraries (I mentioned Glib and QCore) are providing common abstractions to fit into Linux and into Windows, so if you want to develop software portable to Windows and to Linux I suggest using these libraries instead (use them both on Windows and on Linux).

(I also suspect that Microsoft would use legal threats -patent or copyright based- to avoid that free clone of their proprietary dos.h, given their monopolistic reputation and their aversion to standards and to free software; I admit I have strong opinions against Microsoft..)

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
0

#include<dos.h> is not available for Linux but if you want to use dos.h for displaying the time you can use the system function and do it like this

prototype -> system(command);

system("date +%H:%M:%S");

if you want your program to sleep for a specific seconds try this

system("sleep 3") //sleep for a 3 seconds

or use this

std::this_thread::sleep_for(std::chrono::milliseconds(100));

but you have to include the thread header file #include<thread>