@ECHO OFF
@cls
@set wpisane1=
@for /f "tokens=1" %%a in ('type C:\zadanie\1.txt ') do @echo %%a
@echo ma
@set wpisane2=
@for /f "tokens=3" %%b in ('type C:\zadanie\1.txt ') do @echo %%b
@echo lat
@echo.
@set wpisane3=
@for /f "tokens=5" %%c in ('type C:\zadanie\1.txt ') do @echo %%c
@echo ma
@set wpisane4=
@for /f "tokens=7" %%d in ('type C:\zadanie\1.txt ') do @echo %%d
@echo lat
@echo.
@set a1=29
@set a2=35
@set /a suma=%a1%+%a2%
@echo Razem maja %suma% lat(a)
@pause
@exit
我的问题是:如何将%%b
和%%d
设为a1
和a2
?我怎样才能做到这一点?可能吗 ?请尽快回答我的问题。文本文件包含:
radek ma 29 lat jarek ma 35 lat
答案 0 :(得分:1)
尽快?花一点时间学习,从下一个代码片段的结果开始。
@ECHO OFF >NUL
@SETLOCAL enableextensions enabledelayedexpansion
for /f "tokens=1-8*" %%g in ('type C:\zadanie\1.txt') do (
rem set /a "a1=%%i"
rem set /a "a2=%%m"
rem set /a "suma=!a1!+!a2!"
set /a "suma=%%i+%%m"
@echo g=%%g h=%%h i=%%i j=%%j k=%%k l=%%l m=%%m n=%%n o=%%o suma=!suma!
)
@ENDLOCAL
goto :eof