File input/output: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 32: Line 32:




==[[ Tcl/Tk ]]==
==[[Tcl/Tk]]==
'''Interpreter:''' [[tclsh]], [[eTcl]], [[wish]], [[tixwish]]
'''Interpreter:''' [[tclsh]], [[eTcl]], [[wish]], [[tixwish]]
'''Operating System:''' [[UNIX]], [[Linux]], [[BSD]], [[Windows]], [[WinCE]], [[PocketPC]], [[Mac]], [[BeOS]]
'''Operating System:''' [[UNIX]], [[Linux]], [[BSD]], [[Windows]], [[WinCE]], [[PocketPC]], [[Mac]], [[BeOS]]


# open file for writing
#open file for writing
set myfile [open "README.TXT" w]
set myfile [open "README.TXT" w]
# write something to the file
#write something to the file
puts $myfile "This is line 1, so hello world...."
puts $myfile "This is line 1, so hello world...."
# close the file
#close the file
close $myfile
close $myfile




# open file for reading
#open file for reading
set myfile [open "README.TXT" r]
set myfile [open "README.TXT" r]
# read something from the file
#read something from the file
gets $myfile mydata
gets $myfile mydata
# show what was read from the file
#show what was read from the file
# should print "This is line1, so hello world...."
#should print "This is line1, so hello world...."
puts $mydata
puts $mydata
# close the file
#close the file
close $myfile
close $myfile

Revision as of 01:53, 17 January 2007

Task
File input/output
You are encouraged to solve this task according to the task description, using any language you may know.

In this task, the job is to create a file called "output.txt", and place in it the contents of the file "input.txt".

Perl

Interpreter: Perl 5.8.8

#!/usr/bin/perl -w

open INPUT, "<input.txt";
open OUTPUT, ">output.txt";

while ( <INPUT> ) {
  print OUTPUT $_;
}

mIRC

Compiler: mIRC

 alias Write2FileAndReadIt {
 .write myfilename.txt Goodbye Mike!
 .echo -a Myfilename.txt contains: $read(myfilename.txt,1)
 }

UNIX Shell

Interpreter: Bourne Again SHell Operating System: UNIX

#!/usr/bin/bash

cat input.txt > output.txt


Tcl/Tk

Interpreter: tclsh, eTcl, wish, tixwish Operating System: UNIX, Linux, BSD, Windows, WinCE, PocketPC, Mac, BeOS

#open file for writing
set myfile [open "README.TXT" w]
#write something to the file
puts $myfile "This is line 1, so hello world...."
#close the file
close $myfile


#open file for reading
set myfile [open "README.TXT" r]
#read something from the file
gets $myfile mydata
#show what was read from the file
#should print "This is line1, so hello world...."
puts $mydata
#close the file

close $myfile