File handling

Hi,

Please help in file handling syntax in SV like opening a file to write,and opening a file to read?

Thanks,
Syed Taahir

In reply to syed taahir ahmed:

Hi Syed Taahir,

Here are some functions you can use:
$fopen() - to open a file
$fclose() - to close a file
$fdisplay() - to write into a file
$fgetc() - to read a character at a time
$fgets() - to read a line at a time

A little example:


integer file_handle;
string file_name = "path/to/file.txt";
integer character;
string line_to_read;
integer nof_lines_read;

file_handle = $fopen(file_name);
$fdisplay(file_handle,"Write something in file");
character = $fgetc(file_handle);
nof_lines_read = $fgets(line_to_read, file_handle);
$fclose(file_handle);

Thank you,
Claudia Iancu