THANKS!
: : I am just not really understanding this code. Apparently it creates a file, called file2.txt (which is SO cool). But what is Filein, Fileout, and Mychar? What do the do? I can see that MYCHAR goes to FILEOUT and is written to FILE2.TXT, but what does FILEIN in do? Is there a way to read input from a user and create a file? Can someone just explain the code to me? Like comment it and show what it does?
: :
: : Thanks! All help is appreciated!
: : -JIM
: :
: :
: :
: : program CopyOneByteFile;
: :
: : var
: : mychar : char;
: : filein, fileout : text;
: :
: : begin
: : assign (filein, 'c:\file1.txt');
: : reset (filein); { place file-cursor to first character }
: : assign (fileout, 'c:\file2.txt');
: : rewrite (fileout); { create/recreate the file "file2" }
: : read (filein, mychar); { read the first character of "file1.txt" }
: : write (fileout, mychar); { write the character to "file2.txt" }
: : close(filein); { close both files }
: : close(fileout)
: : end.
: :
: :
: :
: This code copies the first character in the file1.txt to file2.txt. FileIn is a text-file variable, which in this case is opened to be read from. The FileOut is also a text-variable, which is opened to write to. (both times see help on Assign). Here is a similar code which allows the user to type a single line and saves it to a file.
:
: var
: line: string;
: userfile: text;
: begin
: Write('Type something: ');
: Readln(line); { get the user input }
: Assign(userfile, 'myfile.txt');
: Rewrite(userfile); { create "myfile.txt" for writing }
: Writeln(userfile, line); { write the user input to the file }
: Close(userfile); { close the file }
: end;
:
:
: