Guest
I have problem in reading the file using $fscanf system function.
I am trying to read the read_pattern.txt file using $fscanf and
displaying the contents of the file.
read_pattern.txt is like this
101 100 25
110 111 32
The source code is
`define NULL 0
`define EOF 32'hFFFF_FFFF
module read_pattern;
integer c, r;
reg [2:0] bin1,bin2;
reg [8*10:1] str;
integer int,line;
integer file;
//reg [8*`MAX_LINE_LENGTH:0] line; /* Line of text read from file */
initial
begin : file_block
$display("Bin1 Bin2 Int");
file = $fopen("read_pattern.txt","r");
if (file == `NULL) // If error opening file
disable file_block; // Just quit
r = 1;
while (r!==0)
begin
r = $fscanf(file," %b %b %d ", bin1,bin2,int);
$display ("Bin1 = %b Bin2 = %b Int = %d\n",bin1,bin2,int);
end // while not EOF
$system("cp read_pattern.txt output.log");
$fclose(file);
$finish;
end // initial
endmodule // read_pattern
When i invoke simulation command it is not stopping after displaying
the 2 lines.
The last line contents are continuosly displaying the with out exiting
the while loop.
Please explain why it is not exiting the while loop.
The simulation output is like this.
Bin1 = 101 Bin2 = 100 Int =25
Bin1 = 110 Bin2 = 111 Int =32
Bin1 = 110 Bin2 = 111 Int =32
Bin1 = 110 Bin2 = 111 Int =32
Bin1 = 110 Bin2 = 111 Int =32
Bin1 = 110 Bin2 = 111 Int =32
.......................
Regards
Vishnu
I am trying to read the read_pattern.txt file using $fscanf and
displaying the contents of the file.
read_pattern.txt is like this
101 100 25
110 111 32
The source code is
`define NULL 0
`define EOF 32'hFFFF_FFFF
module read_pattern;
integer c, r;
reg [2:0] bin1,bin2;
reg [8*10:1] str;
integer int,line;
integer file;
//reg [8*`MAX_LINE_LENGTH:0] line; /* Line of text read from file */
initial
begin : file_block
$display("Bin1 Bin2 Int");
file = $fopen("read_pattern.txt","r");
if (file == `NULL) // If error opening file
disable file_block; // Just quit
r = 1;
while (r!==0)
begin
r = $fscanf(file," %b %b %d ", bin1,bin2,int);
$display ("Bin1 = %b Bin2 = %b Int = %d\n",bin1,bin2,int);
end // while not EOF
$system("cp read_pattern.txt output.log");
$fclose(file);
$finish;
end // initial
endmodule // read_pattern
When i invoke simulation command it is not stopping after displaying
the 2 lines.
The last line contents are continuosly displaying the with out exiting
the while loop.
Please explain why it is not exiting the while loop.
The simulation output is like this.
Bin1 = 101 Bin2 = 100 Int =25
Bin1 = 110 Bin2 = 111 Int =32
Bin1 = 110 Bin2 = 111 Int =32
Bin1 = 110 Bin2 = 111 Int =32
Bin1 = 110 Bin2 = 111 Int =32
Bin1 = 110 Bin2 = 111 Int =32
.......................
Regards
Vishnu