
RASExpress User Guide
166 CommPlete Communications Server
FCREATE fcreate(string file_name) : integer;
Creates the file given in file_name. File_name can include the drive letter and path. If
the file is created, 1 is returned; otherwise 0 is returned. If the file is created, it is
closed and will have to be opened by an fopen call to access it.
Example
/* This script file illustrates fcreate, fopen, fread, */
/* fwrite, fputs, fputc, fgets, fgetc, and fclose commands. */
proc main;
string file_name;
string test_string;
string str;
integer len;
integer count;
integer file_handle;
integer position;
integer offset;
integer origin;
file_name = "tempfile";
if fcreate(file_name) then
fdisplay("%s created^J^M", file_name);
else
fdisplay("%s could not be created^J^M", file_name);
goto error_exit;
endif
/* open the file in read/write mode.*/
file_handle = fopen(file_name, "READWRITE");
if file_handle >= 0 then
fdisplay("%s opened^J^M", file_name);
else
fdisplay("%s could not be opened^J^M");
goto error_exit;
endif
test_string = "example string";
if fputs(file_handle, test_string) then
fdisplay("fputs done^J^M");
else
fdisplay("fputs failed^J^M");
goto error_exit;
endif
if fputc(file_handle, "a") then
fdisplay("fputc done^J^M");
else
fdisplay("fputc failed^J^M");
goto error_exit;
endif
len=4;
if fwrite(file_handle, test_string, len) then
fdisplay("fwrite done^J^M");
else
fdisplay("fwrite failed^J^M");
goto error_exit;
endif
fclose(file_handle);
/* close the file. */
/* open the file in read/write mode. */
file_handle = fopen(file_name, "READWRITE");
if file_handle >= 0 then
fdisplay("%s opened^J^M", file_name);
else
fdisplay("%s could not be opened^J^M", file_name);
goto error_exit;
endif
/* read in characters into a string. */
if fgets(file_handle, str, 3) then
fdisplay("fgets done, string read is :%s^J^M", str);
else
Comentarios a estos manuales