Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

create a file, write texts in it, save it, read its contents

+3 votes
asked Jul 23, 2025 by Lucien Imhof (150 points)
I need instructions, libraries to insert in my program for that.

Thanks in advance for your help.

1 Answer

0 votes
answered Jul 23, 2025 by Peter Minarik (101,340 points)
What programming language are you looking for?
commented Jul 23, 2025 by Lucien Imhof (150 points)
I am sorry to have forgotten that. I am programming in Pascal.
commented Jul 23, 2025 by Peter Minarik (101,340 points)
Old School. Nice. :)

You should find what you're looking for here: https://www.tutorialspoint.com/pascal/pascal_files_handling.htm

If you have written some code and it does not quite work, post your code so we can provide personalized help.

Good luck!
commented Jul 23, 2025 by Lucien Imhof (150 points)
Thank you. I see the displayed result, but I wanted it to be a real file on my PC.

----------------------------------
program writeDemo;

type
   StudentRecord = Record
      s_name: String;
end;

var
   Student: StudentRecord;
   f: file of StudentRecord;

begin
   Assign(f,'c:\tmp\students.dat');
   Rewrite(f);
   Student.s_name := 'John Smith';
   Write(f,Student);
   Close(f);
end.

-----------
I can cut and paste the result into a file on my computer, but is there a simpler way to proceed ?
commented Jul 25, 2025 by Peter Minarik (101,340 points)
I'm afraid, you're right.

OnlineGDB runs the code "online", on a server, so it does not have access to the file system of your local file system.

However, there is an "Upload File" button on the left of the green RUN button, so you can upload files from your PC.

Similarly, there are  "Download Current File" and "Download All Files" buttons with blue all the way to the right.

And copy-paste, as you've mentioned.

Or you can set up a Pascal environment on your local PC.

Unfortunately, I do not see any other alternative. :(
commented Jul 25, 2025 by Lucien Imhof (150 points)
Thank you so much for your help.
Long years ago, I wrote a part of a Portal compiler in Portal, which was very similar to Modula 2. Therefore, my choice was to write my software in Pascal, instead of current languages. Now, with your help, I have exactly what I wanted to solve my problem with my development.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...