dimanche 20 novembre 2016

Nested if in windows batch file cmd

I try to write some simple program in windows batch file. This program is similar to some simple application from "C programming language" Kernighan and Ritchie. The task of this program is to count char numbers and words numbers. Belove there is a source code

rem Char Number and words number
@echo off
cls
echo ===============================================================
echo input strin
set /P a=
::set variables
set Temp_str=%a%
set /A charcounter = 0
set /A wordscounter = 0
:loop
if defined Temp_str (
    set /P actual_char=%Temp_str:~0,1%
    if %actual_char%=="" ( set /A wordscounter+=1 )
    set Temp_str=%Temp_str:~1%
    set /A charcounter+=1;
    goto loop
)
echo %a% %charcounter% %wordscounter%

There is error somewher but I can't find it. I don't know what is wrong. I actually start with batch windows programming.

Aucun commentaire:

Enregistrer un commentaire