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-29 08:56
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch processing to achieve output backspace (Part 2) View 5,507 Replies 32
Floor 16 Posted 2006-12-29 02:57 ·  新西兰 奥克兰大区 奥克兰 Microsoft
高级用户
★★
Credits 783
Posts 268
Joined 2006-12-26 17:18
19-year member
UID 74627
Gender Male
Status Offline
Originally posted by rochan at 2006-12-28 12:55 PM:
There is a slight error in the code on floor 9.. After entering 1 2 3 4 5 6 7 8 in sequence, the k.txt file will have "8642 open ECHO..." instead of "87654321"

I made a change.. Tested and it worked!!
The code is as follows:

@echo o ... 
Floor 17 Posted 2006-12-29 19:09 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 144
Posts 66
Joined 2006-11-30 00:37
19-year member
UID 72121
Gender Male
Status Offline
Floor 9's code has some errors.. After entering 1 2 3 4 5 6 7 8 in sequence, the k.txt file will have 8642 instead of 87654321.

I made a change.. Tested it and it worked!!

The code is as follows:
CODE: [Copy to clipboard]
--------------------------------------------------------------------------------

@echo off
if not exist k.txt echo. >k.txt
:x
set /p a=<k.txt
set /p b=Enter the character:
:::echo %b% >>k.txt
echo %b%%a% >k.txt
goto x


After running, I entered 987, then pressed Enter 3 times in a row, closed the CMD, and opened k.txt to see 777789... Can this problem be improved??
Floor 18 Posted 2006-12-29 19:44 ·  新西兰 奥克兰大区 奥克兰 Microsoft
高级用户
★★
Credits 783
Posts 268
Joined 2006-12-26 17:18
19-year member
UID 74627
Gender Male
Status Offline
Floor 19 Posted 2006-12-30 00:43 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Seeing that foreign batch scripts are written so wonderfully, while looking at our forum's understanding of batch processing just being simple play, it can't help but make some feelings.

Foreign - written batch processing not only has a deep study of algorithms, but is also proficient in the use of the three basic structures. It seems that the Chinese have not studied batch processing so deeply. The reason is that they haven't applied programming ideas to batch processing.

In fact, batch script has very good flexibility, and can even simulate and realize some functions of high - level languages. This is also based on the understanding of data structures in algorithm research. If everyone can do these two points well, I believe that the level of batch processing in the forum can be pushed to a higher level, making batch processing have a wider application range and attracting more people to communicate and learn~!~

I solved this problem using the array method, and of course there is more than one method:


@echo off

setlocal enabledelayedexpansion

set num=0

:go

set /a num+=1

set /p ii%num%=Input %num% number:

if %num% lss 10 goto go

for /l %%i in (%num%,-1,1) do echo !ii%%i!

pause
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
redtek +5 2006-12-30 01:03
zh159 +5 2006-12-30 01:09
lxmxn +6 2006-12-30 05:02
业精于勤而荒于嬉,形成于思而毁于随。
Floor 20 Posted 2006-12-30 01:01 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
It seems that the building owner requires the output to be in the same line, and make a little modification to pengfei's code:

@echo off

setlocal enabledelayedexpansion

set num=0

:go

set /a num+=1

set /p ii%num%=Input %num% number:

if %num% lss 10 goto go

for /l %%i in (%num%,-1,1) do @set/p=!ii%%i!<nul

pause
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +5 2006-12-30 01:25
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 21 Posted 2006-12-30 01:08 ·  中国 河南 许昌 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
21-year member
UID 44210
Status Offline
After all the input in building 19 is completed, it is written to the file. If there is existing content in the original file and you want to add to it, it won't work.

Chinese people are originally not very familiar with English. We can only apply specific methods specifically. Let alone programming (it is estimated that not many people really know how to program).
Floor 22 Posted 2006-12-30 01:36 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Originally posted by zh159 at 2006-12-30 01:08:
The user on floor 19 writes all the content into the file only after completing the input, which doesn't work if you want to add content to an existing file.

Chinese people are originally not very familiar with English, so we can only apply specific methods specifically, let alone programming...


The array has been constructed, and flexible modifications can adapt to various needs.

English is indeed important, but it's not the main reason. Chinese people are good at thinking. The greatest strategists are in China, and China also has first-class mathematicians. But Chinese people can't write excellent compilers, and there are still no geniuses who can independently write operating system kernels. It is undoubtedly a failure of China's education model.

Programming specifically depends on understanding.
业精于勤而荒于嬉,形成于思而毁于随。
Floor 23 Posted 2006-12-30 02:41 ·  中国 北京 联通
银牌会员
★★★
努力做坏人
Credits 1,185
Posts 438
Joined 2006-08-28 12:00
20-year member
UID 61449
From 北京
Status Offline
Agree with Brother pengfei's idea. Indeed, the biggest obstacle in programming is not in the language, but in the thinking and subjective understanding of it. There are many places where we need to learn from others, learning their ways and methods of thinking. We really should reflect on it.
我今后在论坛的目标就是做个超级坏人!!!
Floor 24 Posted 2006-12-30 03:09 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
It seems that Brother 9527 also has the same feeling about this. Algorithms and data structures are profound and extensive. Without in-depth understanding, programming will also be extremely difficult.

The batch processing of the forum needs to learn from foreign peers. Use advanced algorithms to solve problems.
业精于勤而荒于嬉,形成于思而毁于随。
Floor 25 Posted 2006-12-30 03:26 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Not necessarily the more difficult method is the good method. Our purpose is to solve the problem. I think the most important thing for us is the thinking. No matter what method, the more the better. We can't blindly pursue the algorithm
Floor 26 Posted 2006-12-30 04:11 ·  中国 河南 许昌 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
21-year member
UID 44210
Status Offline
Well, okay, need to study. The wordy ones are just...

Recall that some time ago someone posted a segment of code from a foreigner to get the current system date, with a lot of perfect algorithms; while ours is basically two or three lines -_-|||

Use algorithms where they are needed, simplify where they can be simplified

[ Last edited by zh159 on 2006-12-29 at 03:13 PM ]
Floor 27 Posted 2006-12-30 04:34 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
An algorithm is the step to solve a problem. A good algorithm can improve efficiency and simplify the program. Most batch processes posted in the forum are to solve some less complex problems, and maybe the algorithm is not that important. But when doing some complex operations or going beyond the application scope of DOS commands, we have to adopt a roundabout way and use various methods to get the results we want. Then you will feel how important the algorithm is.

It goes without saying that being familiar with various algorithms is important for writing scripts, otherwise, you will be at a loss when encountering complex problems.
业精于勤而荒于嬉,形成于思而毁于随。
Floor 28 Posted 2006-12-30 04:39 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Originally posted by vkill at 2006-12-30 03:26:
Not necessarily the more difficult method is the better method. Our purpose is to solve the problem. I think the most important thing for us is the thinking. No matter what method, the more the better. We can't blindly pursue algorithms.


Algorithms are the steps to solve problems. Brother emphasizes the importance of the thinking to solve problems. Isn't it contradictory to not being able to blindly pursue algorithms?

The ultimate purpose of researching algorithms is to write programs or scripts with high running efficiency and concise code.

It is impossible to write complex scripts without a good algorithm.

[ Last edited by pengfei on 2006-12-30 at 04:41 AM ]
业精于勤而荒于嬉,形成于思而毁于随。
Floor 29 Posted 2006-12-30 04:43 ·  中国 河南 许昌 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
21-year member
UID 44210
Status Offline
Well, but to really understand thoroughly, one still needs to put in hard work (time + energy, etc.)
Floor 30 Posted 2006-12-30 05:26 ·  中国 北京 朝阳区 联通
高级用户
★★
朦胧的世界
Credits 579
Posts 218
Joined 2006-10-24 04:29
19-year member
UID 67972
Status Offline
The code on the 19th floor is actually just about reversing the input and output, but it's not very suitable for the original poster's question. And the solution on the 13th floor has basically been given.

There are multiple ways to solve problems, but there's no need to blindly pursue the "advanced nature" of algorithms. After all, whether a program is good or not isn't judged by how complex its algorithm is, but by the effect of it solving the problem. Using "simple and practical" methods to solve problems is precisely the advantage of batch processing.


@echo off
if not exist k.txt echo. >k.txt
:x
set b=
set /p a=<k.txt
set /p b=输入的字符:
if "%b%"=="" goto :eof
echo %b%%a% >k.txt
goto x


[ Last edited by tao0610 on 2006-12-29 at 04:28 PM ]

认识自己,降伏自己,改变自己
,才能改变别人!
Forum Jump: