China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 04:30
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » How to read and write DOS variables in C? View 1,533 Replies 3
Original Poster Posted 2008-12-27 22:12 ·  中国 广东 广州 越秀区 电信
初级用户
Credits 28
Posts 14
Joined 2008-12-24 22:30
17-year member
UID 134838
Gender Male
Status Offline
How does C read and write DOS variables?
Or, how can a program written in C read/modify DOS variables or assign the return value to a DOS variable?

For example, there is a variable in DOS: vCdrom=D:, but I just want the first character. C can use the left() function to intercept, but there seems to be no such command in DOS.
Floor 2 Posted 2009-01-07 18:05 ·  中国 广东 中山 电信
新手上路
Credits 16
Posts 8
Joined 2007-10-09 14:50
18-year member
UID 99265
Gender Male
Status Offline
DOS doesn't have such a function. Write a conversion program in C.
Floor 3 Posted 2009-01-08 11:09 ·  中国 北京 联通
高级用户
★★
Credits 506
Posts 187
Joined 2005-12-04 22:41
20-year member
UID 46500
Gender Male
Status Offline
I don't understand what you mean.
But it can be implemented as follows.
For example, you have a program A.exe, and after it finishes, it returns a value, such as maybe 1 or 2.
Execute different programs B.exe or C.exe according to your return value.

It can be implemented through batch processing.

A.exe(Execute A)
if errorlevel 2 goto L_2
if errorlevel 1 goto L_1
goto L_end
:L_2
C.exe
goto L_end
:L_1
B.exe
goto L_end
:L_end
Floor 4 Posted 2009-01-16 15:49 ·  IANA 本机地址
新手上路
Credits 11
Posts 6
Joined 2009-01-04 20:38
17-year member
UID 135781
Gender Male
Status Offline
Try the main program return value.

int main()
{
int x=0;
....

retun x;
}
Forum Jump: