Write in output file



OK,  it works ! 

Thanks 


---------------------------------------------------------------------------------

Am 18 Dec 2006 um 15:39 hat roberto.candon at mediolanum.it geschrieben:

> And I want to write the result in an output file:
>
> I think :
>
> f : ?open (?"c:\temp\fileout.txt")$
> for i:0 step 1 thru 10 do ( if i>4 then print("factors of ",i," are 
",factor(i)));
> ?close (?f);
>
> Can you help me, plese ?

Hi Roberto,

there are at least three possibilities to output your results to file.

1. functions with_stdout and print:
          (%i1) with_stdout ("tmp.out", for i:5 thru 10 do print (i, "! 
yields", i!))$
          (%i2) printfile ("tmp.out")$
          5 ! yields 120
          6 ! yields 720
          7 ! yields 5040
          8 ! yields 40320
          9 ! yields 362880
          10 ! yields 3628800

2. functions from stringproc-package:
(%i1) load("stringproc")$
(%i2) stream: openw("E:/file.txt");
(%o2)                          #<output stream E:/file.txt>
(%i3) for i:5 thru 10 do printf( stream, "factors of ~2d are ~a~%", 
i,factor(i) );
(%o3)                                         done
(%i4) close(stream);
(%o4)                                         true
(%i5) printfile("E:/file.txt");
factors of  5 are 5
factors of  6 are 2*3
factors of  7 are 7
factors of  8 are 2^3
factors of  9 are 3^2
factors of 10 are 2*5
(%o5)                                      E:/file.txt

3. the package numericalio also provides I/O-functions