module astar ();
int file,c,n,m,i;
string filename;
int q[$];
initial
begin
//Get the file name
if($value$plusargs("filename=%s", filename));
else filename = "tmp.txt";
// Read file a char at a time
file = $fopen(filename,"r");
while (!$feof(file)) begin
c = $fgetc(file);
if (c != " " && c != "\n") begin
q.push_back(c);
$display(" %0dth Char is = %s ",i++,c);
end
end
foreach (q[i]) $display ("q[%0d] = %s",i,q[i]);
//Get nodes from file
n = q.pop_front() ;
m = q.pop_front() ;
$display(" Maze Dimensions are %0d X %0d ",n,m);
end
endmodule
I’m getting right value from the file, but when I pop from queue and assign to local variable, getting some weird value.
When you are reading the values, you are reading them as characters and displaying them as characters as well. When you pop them, you are displaying their decimal values.
For ASCII characters, “3” is hex 0x33 and decimal 51. “5” is hex 0x35 and decimal 53, which corresponds to how you are displaying the Maze dimensions.
6.16.9 Atoi(), atohex(), atooct(), atobin()
function integer atoi();
function integer atohex();
function integer atooct();
function integer atobin();
— str.atoi() returns the integer corresponding to the ASCII decimal representation in str. For
example:
str = “123”;
int i = str.atoi(); // assigns 123 to i.
// Read file a char at a time
file = $fopen(filename,"r");
while (!$feof(file)) begin
code = $fscanf(file,"%s",c);
q.push_back(c);
$display(" %0dth Char is = %s ",i++,c);
end