can i make a program in c++ work on dos

i need to make a program work on dos

Page 1 of 1

9 Replies - 3316 Views - Last Post: 09 December 2009 - 04:06 AM Rate Topic: -----

#1 professor_pr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-December 09

can i make a program in c++ work on dos

Post icon  Posted 08 December 2009 - 08:21 AM

Hi gues i need to make a program work on dos :pirate: in c++ can someone help me ...plz
Is This A Good Question/Topic? 0
  • +

Replies To: can i make a program in c++ work on dos

#2 Ancient Dragon  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 81
  • View blog
  • Posts: 679
  • Joined: 19-July 09

Re: can i make a program in c++ work on dos

Posted 08 December 2009 - 08:28 AM

DOS stands for Disk Operating System. Most operating systems have one, such as MS-Windows, Unix, Linux, MAC, OS/2, etc. So you need to clarify what you mean. And yes, all c and c++ programs work with dos, afterall that's where they are stored.

This post has been edited by Ancient Dragon: 08 December 2009 - 08:28 AM

Was This Post Helpful? 0
  • +
  • -

#3 professor_pr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-December 09

Re: can i make a program in c++ work on dos

Posted 08 December 2009 - 08:41 AM

View PostAncient Dragon, on 8 Dec, 2009 - 07:28 AM, said:

DOS stands for Disk Operating System. Most operating systems have one, such as MS-Windows, Unix, Linux, MAC, OS/2, etc. So you need to clarify what you mean. And yes, all c and c++ programs work with dos, afterall that's where they are stored.

-I mean i want to make a simplest windows i made a program in DevC++ and i need work on dos if i put the program in cd he de dose not work
Was This Post Helpful? 0
  • +
  • -

#4 galorin  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 86
  • Joined: 17-February 09

Re: can i make a program in c++ work on dos

Posted 08 December 2009 - 09:29 AM

View Postprofessor_pr, on 8 Dec, 2009 - 07:41 AM, said:

View PostAncient Dragon, on 8 Dec, 2009 - 07:28 AM, said:

DOS stands for Disk Operating System. Most operating systems have one, such as MS-Windows, Unix, Linux, MAC, OS/2, etc. So you need to clarify what you mean. And yes, all c and c++ programs work with dos, afterall that's where they are stored.

-I mean i want to make a simplest windows i made a program in DevC++ and i need work on dos if i put the program in cd he de dose not work


ok, I'm not sure what you've made, since I can't make sense of what you've said. With DOS, as any other console-only application, you won't have access to any window manager. You won't be able to make dialog boxes or anything of that sort without putting in a lot of work, probably more than you have done so far.

I've done limited console application stuff, so there might be more utilities, but the basics are printing to screen with printf or maybe cout if you are using C++. So, what exactly are you trying to do?

Please try to make sense this time.
Was This Post Helpful? 0
  • +
  • -

#5 professor_pr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-December 09

Re: can i make a program in c++ work on dos

Posted 08 December 2009 - 10:35 AM

Example i want this code work on dos i want make a simlest windows include claender & clock &culcater and more like this
#include "conio"
#include "stdlib"
#include "dos"
#include "string"
#include "stdio"
#include "iostream"
using namespace std;

void draw(int, int);		  //DRAWS BOX WITH MONTH & YEAR IN HEADER
void show_time();	 		//DISPLAYS CURRENT TIME IN FOOTER OF BOX
void print_cal( int, int); //PRINTS DATES WITHIN BOX
int getkey();			  //SCANS USER KEY AND RETUEN ITS SCAN CODE
int first_day( int, int ); //DETEMINES FIRST DAY OF MONTH
int today;

void main()
{
	int year, month;
	char ch;
	struct date d;
	getdate(&d);		//RETURNS CURRENT DATE
	year = d.da_year;
	month = d.da_mon - 1;
	today = d.da_day - 1;	 //GET CURRENT DATE
	print_cal(year, month); //PRINTS CALENDER OF CURRENT MONTH
	flushall();
	while((ch = getkey()) != 1) //KEEP TRACK OF KEYS UNTILL 'ESC' PRESSED
	{
		switch(ch)
		{
			case 72: year++;  //UP ARROW KEY
						break;
			case 80: year--; //DOWN ARROW KEY
						break;

			case 77: month++;		//RIGHT ARROW KEY
						if(month > 11)
						{
							month = 0;
							year++;
						}
						break;
			case 75: month--;	   //LEFT ARROW KEY
						if(month < 0)
						{
							month = 11;
							year--;
						}
						break;
		}
		print_cal(year, month);  //PRINTS CALENDER OF CHANGED MONTH OR YEAR
	}
}
void show_time()
{
	struct  time t;
	while(!kbhit())
	{
		textcolor(YELLOW);
		gettime(&t);			  //GET CURRENT TIME
		gotoxy(22,2);
		if(t.ti_hour < 13)
			printf(" CURRENT TIME => %2d:%02d:%02d AM",t.ti_hour, t.ti_min,
t.ti_sec);
		else
		{
			t.ti_hour -= 12;
			printf(" CURRENT TIME => %2d:%02d:%02d PM",t.ti_hour, t.ti_min,
t.ti_sec);
		}

		delay(1000);
	}
}

int first_day(int year, int month)  //DETEMINES FIRST DAY OF MONTH
{
	int mdays[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 
334};
	int lpyear = ((year-1900)/4) + ((year-1900)/400) - ((year-1900)/100);
	long unsigned days = ((year-1900)*365) + lpyear + mdays[month];
	return days % 7;
}
int getkey()	//SCANS USER KEY AND RETURN ITS SCAN CODE
{
	union REGS i,o;
	while(!kbhit())
	;
	i.h.ah = 0;
	int86(22,&i,&o);
	return(o.h.ah);
}
void draw(int year, int month) //DRAWS BOX WITH MONTH & YEAR IN HEADER
{
	char *mo[] = { "January", "Feburary", "March", "April",
						"May", "June", "July", "August", "September",
						"October",  "November", "December" };
	char *day[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	int i, j;
	int ro = 205, co = 186;  //GARPH CHAR 205 '', 186 ''
	clrscr();
	gotoxy(16, 8);
	printf("USE ARROW KEYS TO NAVIGATE AND ESC KEY TO CLOSE");
	for( i = 16; i <= 65; i++)
	{	gotoxy(i,10);
		printf ("%c",ro);
		gotoxy(i,14);
		printf ("%c",ro);
		gotoxy(i,36);
		printf ("%c",ro);
		gotoxy(i,40);
		printf ("%c",ro);
	}
	for(i = 11; i <= 39; i++)
	{	gotoxy(15,i);
		printf ("%c",co);
		gotoxy(66,i);
		printf ("%c",co);
	}
	gotoxy(15,10);
	printf("%c",201);  //GARPH CHAR 201 ''
	gotoxy(66,10);
	printf("%c",187);  //GARPH CHAR 187 ''
	gotoxy(15,40);
	printf("%c",200);  //GARPH CHAR 200 ''
	gotoxy(66,40);
	printf("%c",188);  //GARPH CHAR 188 ''
	gotoxy(15,14);
	printf("%c",204);  //GARPH CHAR 204 ''
	gotoxy(66,14);
	printf("%c",185);  //GARPH CHAR 185 ''
	gotoxy(15,36);
	printf("%c",204);  //GARPH CHAR 204 ''
	gotoxy(66,36);
	printf("%c",185);  //GARPH CHAR 185 ''

	textcolor(YELLOW + BLINK);
	int hed_sp = 16 +((49 - (strlen(mo[month]) + 5))/2); //ALLIGN HEADER 
TO
CENTER
	gotoxy(hed_sp,12);
	cprintf("%s %d",mo[month],year);
	window(16,15,65,35);
	clrscr();
	for(i=1, j = 0; i<49; i+=7,j++) //PRINT DAY NAMES
	{
		  if(i < 7)
		textcolor(RED); // FOR SUNDAY
		  else
		textcolor(YELLOW); //OTHER THAN SUNDAY
		gotoxy(i,3);
		cprintf("%5s",day[j]);
	}
}
void print_cal(int year, int month)
{
	int i, j, start, count, limit;
	textmode(64);
	start = first_day(year, month);
	count = 0, limit = 31;
	draw(year, month);
	if( month == 3 || month == 5 || month == 8 || month == 10 )
	limit = 30;	 //FOR APRIL, JUNE, SEPT, NOV
	if(month == 1 ) //FOR FEB
		limit = (year% 4==0 && year%100 != 0 || year%400==0)? 29: 28;
	for(j=7; j< 20; j+=3) //ROW COUNTER
	{
	  for(i=1; i<49; i+=7) //COLUMN COUNTER
	  {
			if(i < 7)
				textcolor(RED);	 //DATES ON SUNDAY
			else
				textcolor(YELLOW);
			gotoxy(i,j);
			if(start)
				start--;	 //EMPTY SPACES TILL NUMBERING STARTS
			else
			{
				if(count == today)	  //HILIGHT CURRENT DATE
				{
					textcolor(BLUE);
					textbackground(YELLOW);
				}
				else
				{
					textcolor(YELLOW);
					textbackground(BLACK);
				}
				cprintf("%4d",count+1);   //PRINT DATE
				count++;
			}
			if(count >= limit)
				break;
		}
	}
	if(count <= 30 && count < limit) //FOR PRINTING IN FIRST ROW IF ALL 
ROWS
EXUASTED
	{  for(i=1; i<49; i+=7)
		{
		if(i < 7)
			textcolor(RED);
		else
			textcolor(YELLOW);
		gotoxy(i,7);
		if(count == today)
		{
			textcolor(BLUE);
			textbackground(YELLOW);
		}
		else
		{
			textcolor(YELLOW);
			textbackground(BLACK);
		}
		cprintf("%4d",count+1);
		count++;
		if(count >= limit)
		break;
		}
	}
	window(16,37,65,39);  //SETS WINDOW TO BOTTOM OF BOX
	show_time();		  //SHOWS TIME
}


Thank you for your help
Was This Post Helpful? 0
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: can i make a program in c++ work on dos

Posted 08 December 2009 - 10:36 AM

Well dos is kind of old tech. To really get a program to run in true DOS (not windows) you will probably have to compile it using an old DOS compiler. There are two that I know of out there, Turbo C++ 3.0 and DJGPP both are available for download.

The DJGPP is probably a little newer, it is a 32bit compiler and generates 32bit code (80386 or better) but if you look in the "older tools" area of thier site you can find the 16bit tools which would be universally available to DOS.

I think maybe the Digital Mars compiler may also work... I know it still produces windows 98 style windows programs, so I *think* it may be able to produce a true DOS exe/com.


BUT -- by DOS do you really mean MS-DOS 3.1 or MS-DOS-5 or MS-DOS 6.1 -- Because if by "DOS" you just mean a windows dos prompt, then any modern compiler you choose will work.

Though you know it IS possible to generate a single PE (a .exe file) that should work in BOTH environments. This would take some pretty technical knowledge but every windows EXE actually contains a small MS-DOS stub. This stub normally prints a message saying that this program requires MS-Windows to run. BUT if you were to create your own stub (I would imagine you would have to use Assembly...) you could probably get a linker to use that instead of its default...

Though as I said this would really take some pretty technical knowledge (I *think* I could do it, but I don't think I could explain it to anyone... and I would allow myself at least 2 weeks just to get things setup. Writing the code would be the easy part, getting a viable PE out of the linker would be the hard part... one may have to let the linker produce a normal windows PE and then "update it" withe the new DOS code after it was linked.)
Was This Post Helpful? 0
  • +
  • -

#7 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: can i make a program in c++ work on dos

Posted 08 December 2009 - 10:48 AM

OK... what is your target OS? windows xp, windows vista, windows 3.1, dos 3.1?
Was This Post Helpful? 0
  • +
  • -

#8 Ancient Dragon  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 81
  • View blog
  • Posts: 679
  • Joined: 19-July 09

Re: can i make a program in c++ work on dos

Posted 08 December 2009 - 02:47 PM

Also note that there is no such operating system called "DOS". That is not an operating system. It's a Disk Operating System that runs other operating systems such as MS-Windows, Linx, Unix, OS/2, MAC, etc . etc .

If what you mean by DOS is one of Microsoft's products then the correct term is MS-DOS, and that only applies to version 6.X and earlier. Every version of MS-Windows since Win98 has not supported MS-DOS.

#include "conio"
#include "stdlib"
#include "dos"
#include "string"
#include "stdio"



There four things wrong with the above statements
1) Those files must have .h extension, such as conio.h. There is no such file as conio, stdlib, dos, etc.

2) Those file names should be surrounded by angle brackets < and >, not quotes. #include <conio.h>.

3) "string" could be either <string> (C++ header file) or <stirng.h> which is a C header file. Those are two completely different header files, and they can both be included if you want (depending on your needs).

4) dos.h is a very old header file supported by 16-bit compilers such as Turbo C and Microsoft's C++ 1.52C, Lattice, and a few others. It contains function prototypes and macros that are only useful in 16-bit MS-DOS operating system. They are not supported in MS-Windows and modern compilers will produce errors with them.

This post has been edited by Ancient Dragon: 08 December 2009 - 02:51 PM

Was This Post Helpful? 0
  • +
  • -

#9 professor_pr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-December 09

Re: can i make a program in c++ work on dos

Posted 09 December 2009 - 04:00 AM

View PostAncient Dragon, on 8 Dec, 2009 - 01:47 PM, said:

Also note that there is no such operating system called "DOS". That is not an operating system. It's a Disk Operating System that runs other operating systems such as MS-Windows, Linx, Unix, OS/2, MAC, etc . etc .

If what you mean by DOS is one of Microsoft's products then the correct term is MS-DOS, and that only applies to version 6.X and earlier. Every version of MS-Windows since Win98 has not supported MS-DOS.

#include "conio"
#include "stdlib"
#include "dos"
#include "string"
#include "stdio"



There four things wrong with the above statements
1) Those files must have .h extension, such as conio.h. There is no such file as conio, stdlib, dos, etc.

2) Those file names should be surrounded by angle brackets < and >, not quotes. #include <conio.h>.

3) "string" could be either <string> (C++ header file) or <stirng.h> which is a C header file. Those are two completely different header files, and they can both be included if you want (depending on your needs).

4) dos.h is a very old header file supported by 16-bit compilers such as Turbo C and Microsoft's C++ 1.52C, Lattice, and a few others. It contains function prototypes and macros that are only useful in 16-bit MS-DOS operating system. They are not supported in MS-Windows and modern compilers will produce errors with them.

Thank you but i wrote this program quiqly its just an example
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5363
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: can i make a program in c++ work on dos

Posted 09 December 2009 - 04:06 AM

Rather than just blindly asking for code, why don't you have a look at our snippets & tutorials?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1