Pascal guide - File-handling

    Today pascal guide will talk about  File handling:
    first we will talk about assign function and read/write function:

 assign is a function that copy the external file content
to internal text variable,the delcaration like this:
assign(variable, file name);
 let's go for the read function:
 first ,when we want to read a file,we must be
   reset the file variable,and also read/readln function are used to read
like this
 sample 1:
  var
    abc:text;
    content:string;
 begin
   assign(abc,' BBQ.TXT'); {first BBQ.txt must be
                                       persent because of reading
                                        according to the function reset}
   reset(abc);
   readln(abc,content);      {then we use readln function to read a line in variable}
                                      {If there are many lines in the program,or storing a article, a LOOPING and array of "content" may be used for read the data.}
   writeln('file content:',content );{output content}
   close(abc);{remember to close the abc before program end!! else the file may dead(data lost)!!
 end.
 let's go for the write function: a rewrite function is needed to replace
the reset function,
 sample2:
 var
  abc:text;
  content:string;
 begin
   assign(abc,' BBQ.TXT'); {BBQ.txt can be absent ,if absent ,PASCAL will help you to create a new one else the pascal will overwrite the old one according to the function rewrite}

   rewrite(abc);
   writeln('please enter a text here(1-79)');
   readln(content);
   writeln(abc,content);      {then we use writeln function to put  a variable in line}
   writeln('file content added:',content );{output content}
   close(abc);
 end.
 when you want to completly kick out a file,Don't use dummy variable for writing instead, use the function "Erase(variable text)" is most approriate!!

that's the end of this day, next day(sure?) we will talk about record and two data structure (linked list and list)

<< Previous || Next >>