![](/images/backgrounds/286549/hp-sunsoft-pascal-4-0-users-manual-549395158x1.png)
6
The commands to compile and execute GloVar.p and GloVarMain.c without
hostname% pc
hostname% a.out 2001
File-Passing Between Pascal and C
You can pass a file pointer from Pascal to C, then have C do the I/O, as in:
The C procedure, | #include <stdio.h> |
UseFilePtr.c |
|
| void UseFilePtr (FILE *ptr) |
| { |
| { /* Write to the file: */ |
| fprintf( ptr, "[1] Passing the file descriptor \n") ; |
| fprintf( ptr, "[2] and writing information \n") ; |
| fprintf( ptr, "[3] to a file \n") ; |
| } |
|
|
The Pascal main program, UseFilePtrMain.p
program UseFilePtrMain; var
f: text;
cfile: univ_ptr;
procedure UseFilePtr(cf: univ_ptr); external c;
begin
rewrite(f, 'myfile.data'); | { Make the file. } |
cfile := getfile(f); | { Get a file pointer. } |
UseFilePtr(cfile); | { Call the C function. } |
end. { UseFilePtrMain } |
|
134 | Pascal 4.0 User’s Guide |