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-13 02:03
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Urgent: how do I accept a string entered from the keyboard?!!! View 867 Replies 10
Original Poster Posted 2003-08-08 00:00 ·  中国 台湾 中华电信
中级用户
Credits 283
Posts 39
Joined 2003-07-12 00:00
23-year member
UID 6808
Gender Male
Status Offline
I want DOS to prompt me to input a string:
After I enter characters and press Enter, the characters entered will be saved in a file.
like this the screen displays
please in put string:
I enter
ddddd
After that, I can get ddddd in some .txt file
Then ask for confirmation input:
please put string again
If this input is different from the first one, then report an error.
Thanks, I sincerely ask everyone to help
我不是菜,是汤!!!
Floor 2 Posted 2003-08-08 00:00 ·  中国 福建 福州 电信
元老会员
★★★
农民
Credits 2,903
Posts 991
Joined 2003-07-23 00:00
23-year member
UID 7391
Gender Male
From 福建省
Status Offline
I think this has to be solved through programming...
The general idea is like this: first set up a loop, then output “Please input string:” on the screen, save the string entered by the user in a variable, then output “Please put string again:” on the screen and ask the user to enter it again, compare that data with the previous variable, and if they are the same then save it to some .txt file; if they are different then report an error.
This is only a brief idea. It should be very easy to do with a programming language.
艰难奋长戟,万古用一夫

中国DOS联盟 http://www.cn-dos.net 欢迎大家来共同学习
我的MSN&E-Mail cn_archer@hotmail.com QQ 56049418
Floor 3 Posted 2003-08-08 00:00 ·  中国 台湾 中华电信
中级用户
Credits 283
Posts 39
Joined 2003-07-12 00:00
23-year member
UID 6808
Gender Male
Status Offline
The key is how to store the characters entered on the screen into a variable!!!!!!!!
How do I set it?
Could you give the program?
我不是菜,是汤!!!
Floor 4 Posted 2003-08-08 00:00 ·  中国 福建 福州 电信
元老会员
★★★
农民
Credits 2,903
Posts 991
Joined 2003-07-23 00:00
23-year member
UID 7391
Gender Male
From 福建省
Status Offline
Hehe, this step is very simple.
I don't remember C or other programming languages too clearly now, so let me try describing it using database language.

store space(6) to x //this 6 mainly refers to how many positions it occupies; you can set it yourself
@10,10 say“Please input string:” get x picture "XXXXXX"
read

That will do it. I think things like input in C can also achieve this, but I don't remember the exact commands too clearly, so I can only give a rough idea, :)
艰难奋长戟,万古用一夫

中国DOS联盟 http://www.cn-dos.net 欢迎大家来共同学习
我的MSN&E-Mail cn_archer@hotmail.com QQ 56049418
Floor 5 Posted 2003-08-08 00:00 ·  中国 广东 肇庆 电信
高级用户
★★
Credits 578
Posts 135
Joined 2003-07-10 00:00
23-year member
UID 6709
Gender Male
Status Offline
The following is a quote from lifeng5115 at 2003-8-8 12:29:47:
The key is how to store the characters entered on the screen into a variable!!!!!!!!
How do I set it?
Could you give the program?

Use get plus s
For example:
get s "please in put string:"
This way, %get% in the next line of command is the string you just entered!







Floor 6 Posted 2003-08-11 00:00 ·  中国 台湾 中华电信
中级用户
Credits 283
Posts 39
Joined 2003-07-12 00:00
23-year member
UID 6808
Gender Male
Status Offline
I'd like to ask, can get be used in a batch file???
By accepting input, I mean under DOS
我不是菜,是汤!!!
Floor 7 Posted 2003-08-12 00:00 ·  中国 河南 南阳 联通
初级用户
Credits 219
Posts 23
Joined 2003-08-11 00:00
23-year member
UID 8405
Gender Male
Status Offline
So hard!
Looks like I need to study more!
Floor 8 Posted 2003-08-12 00:00 ·  中国 香港
管理员
★★★★
專業島民
Credits 4,869
Posts 1,633
Joined 2002-12-10 00:00
23-year member
UID 465
Gender Male
Status Offline
The following is a quote from lifeng5115 at 2003-8-8 11:16:52:
I want DOS to prompt me to input a string:
After I enter characters and press Enter, the characters entered will be saved in a file.
like this the screen displays
please in put string:
I enter
ddddd
After that, I can get ddddd in some .txt file
Then ask for confirmation input:
please put string again
If this input is different from the first one, then report an error.
Thanks, I sincerely ask everyone to help

:: Get user input - includes error check
@echo off
set secondpass=
echo e100'set input='>%temp%.\temp.dat
echo w>>%temp%.\temp.dat
echo q>>%temp%.\temp.dat
:input
echo.
if not %secondpass%.==1. echo Type in input
if %secondpass%.==1. echo Type in input again
echo.>%temp%.\temp.bat
FC con nul /lb1 /n |FIND.exe "1:" >> %temp%.\temp.bat
:: Error checking begins here
FIND "|" %temp%.\temp.bat > nul
if not errorlevel=1 goto error
FIND "=" %temp%.\temp.bat > nul
if not errorlevel=1 goto error
FIND " nul
if not errorlevel=1 goto error
FIND ">" %temp%.\temp.bat > nul
if not errorlevel=1 goto error
:: Error checking end
DEBUG %temp%.\temp.bat nul
call %temp%.\temp.bat
if exist %temp%.\temp.?at del %temp%.\temp.?at
rem echo INPUT=%INPUT%
goto EOF
:error
echo.
echo @PROMPT Error - invalid characters: $Q $L $G $B> %temp%.\temp.bat
%comspec% /c %temp%.\temp.bat |FIND.exe "Error:"
goto input
:eof
if not %secondpass%.=1. echo %INPUT%>1st.txt
if not %secondpass%.=1. set secondpass=1
if %secondpass%.=1. type 1st.txt|find "%INPUT%">NUL
if errorlevel 1 goto notmatch
goto end

:notmatch
ECHO The input does not match!
goto end

:end
我的網站:http://mw16.2ya.com/ 我的網誌: http://scrappedblog.blogspot.com/
~
我的Winamp正在播放的歌曲:
Floor 9 Posted 2003-08-13 00:00 ·  中国 广东 肇庆 电信
高级用户
★★
Credits 578
Posts 135
Joined 2003-07-10 00:00
23-year member
UID 6709
Gender Male
Status Offline
No need to make it this complicated, right?
Floor 10 Posted 2003-08-13 00:00 ·  中国 台湾 中华电信(HiNet)数据中心
中级用户
Credits 283
Posts 39
Joined 2003-07-12 00:00
23-year member
UID 6808
Gender Male
Status Offline
Too complicated ^_^
I just want something a bit simpler.
我不是菜,是汤!!!
Floor 11 Posted 2003-10-16 00:00 ·  中国 浙江 金华 电信
中级用户
★★
Credits 278
Posts 52
Joined 2003-06-10 00:00
23-year member
UID 4662
Gender Male
Status Offline
Just use INPUT!
Forum Jump: