Jump to content

edisonx

Member
  • Posts

    5
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    Taiwan

About edisonx

Profile Information

  • OS
    none specified

edisonx's Achievements

0

Reputation

  1. Hi, dear jaclaz : I try your code , it wroks fine "now" . First, I use vc 2008 to compile my C code, there is something wrong !! (It generates execute file, but I can't use it normal). But I use gcc to compile my C code, It's fine !!!! (so suprise !!) I reboot my computer, re-compiler the same code by gcc and vc, then , the batch works fine now. next, I wonder to build all C math / string librarys and some floating operator to cmath.exe. Just because batch can't cal floating and can't using array. allen2, jaclaz, thank you a lot. you help me really very much. again and again.
  2. Hi, jaclaz thank you for your replay. I need some time to study and understand the code that you wrote . and need some time to try those. thank you very much, help me a lot !!
  3. thank you , allen 2. and sorry for I still have another question.. a simple code in C /* pow.c , generate pow.exe */ #include <stdio.h> #include <stdlib.h> #include <math.h> int main(int argc, char **argv) { if(argv!=3) return 1; else printf("%lf", pow( atof(argv[1]), atof(argv[2])) ); return 0; } :: demo.bat pow.exe 1.23 4.56 it will show 2.570202 in console window. but I can't get it in batch-variable. I handle it by redirection to a file, then read the file again :: demo.bat SET c=0 pow.exe 1.23 4.56 > _rst.txt FOR /F %%I IN ( _rst.txt) DO ( SET c=%%I ) del _rst.txt I know, the method is slow and stupid. I just want to know , in batch file, is the method good ? or is any method better than this ? ------ As you said, I want to save the value into a variable,but in C language, it's a big problem, just like this /* filename: pow2.c generate: pow2.exe */ #include <stdio.h> #include <stdlib.h> #include <math.h> int main(int argc, char **argv) { if(argv!=4) return 1; else sprintf(argv[3], "%lf", pow( atof(argv[1]), atof(argv[2])) ); return 0; } I can't do that!! the behavior is very dangerous in C. in batch file @echo off SET rst call pow2.exe 1.23 4.56 rst echo %rst% those codes can't work , because pow2.exe receive argv by argv[0]=pow2.exe argv[1]=1.23 argv[2]=4.56 argv[3]=rst const string, not variable, I can't change its value!! ---- maybe, I should ask another question : 「how to pass the envionment variable to batch file in C ? 」 ---- I know it's a big and studip problem, but I just want to know , how can I write some application in C, and batch file can using it. Thanks for your replies.
  4. thanks for your replay, allen2 . I had studying the website that you gave to me. I really misunderstood pipe '|' , thank you a again. I used to programming in C/C++ language, but learning to use batch command recently by some reasons. I think that there are many instructions in *.h files in C, so what I need , call the instruction just include ???.h file. But in batch, if there is a batch command was used frequently, will it be written down again in different batch files ? just like sum.bat I had ever try this code @echo off :main SET rst=0 call :sum 1 10 rst echo %rst% goto :eof :: -------------------------------- :: param 0 : sum (function name) :: param 1 : low bound :: param 2 : up bound :: param 3 : ans :: -------------------------------- :sum SETLOCAL ENABLEDELAYEDEXPANSION &Rem using local variable SET low=%~1% SET up=%~2% SET rst=0 FOR /L %%i IN (%low%,1,%up%) DO ( SET /A rst+=%%i ) (ENDLOCAL &Rem return value SET %3=%rst% ) goto :eof in this case,if sum function is used frequently, I think that coding it in another .bat is better , right ? I'm confused how to like C language, to make a function-like batch, let other batch files can re-used. Is this the only way to maintain the source ? :: filename : sum.bat :: -------------------------------- :: param 0 : sum (function name) :: param 1 : low bound :: param 2 : up bound :: param 3 : ans :: -------------------------------- :sum SETLOCAL ENABLEDELAYEDEXPANSION &Rem using local variable SET low=%~1% SET up=%~2% SET rst=0 FOR /L %%i IN (%low%,1,%up%) DO ( SET /A rst+=%%i ) (ENDLOCAL &Rem return value SET %3=%rst% ) goto :eof :: filename : demo_sum.bat @echo off :demo_sum SET ret=0 call sum.bat 1 10 ret echo ret=%ret% your reply helps me a lot!! thank you again *^_^*
  5. hello, everyone, I wonder to know , how to using redirection pipe ( | ), so I write three batch files (sum.bat, rstring3.bat main.bat) to test. like those :: filename : sum.bat @echo off :main SET low=%~1% SET up=%~2% SET ret=0 FOR /L %%I IN (%low%,1,%up%) DO ( SET /A ret+=%%I ) echo %low%+...+%up%=%ret% :: filename : rstring3.bat @echo off :main SET String=%1% SET String=%String:~-3% echo %String% :: filename : main.bat rstring3.bat | sum.bat 1 10 in command line, I type C:\> main.bat It wilil display 1+...+10=55 but I think it will display 55 what's wrong with the code ? how can I do to fix the wrong answer ? thanks for everyone, and sorry for my poor English.
×
×
  • Create New...