Feb 5, 2018 #1 J jalal.baba Junior Member level 1 Joined Feb 5, 2018 Messages 16 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 118 Can anyone please help me read decimal(just) values from a text file my text is a.text : Code: 3 4 14 3 24 5 my code is : Code Verilog - [expand]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 `define Lenght 6 integer p,r,c; integer file,stat,out,i; reg [7:0] face[0:`Lenght-1]; initial begin file=$fopen("a.txt","r"); $display ("reading file....."); i=0; while (! $feof(file)) begin stat=$fscanf(file,"%d\n",face[i]); i=i+1; end $fclose(file); for(i=0;i<`Lenght;i=i+1) begin $display("face[i]=%d",face[i]); end end and my results is: 3 4 1 4 3 2 Click to expand... thanks
Can anyone please help me read decimal(just) values from a text file my text is a.text : Code: 3 4 14 3 24 5 my code is : Code Verilog - [expand]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 `define Lenght 6 integer p,r,c; integer file,stat,out,i; reg [7:0] face[0:`Lenght-1]; initial begin file=$fopen("a.txt","r"); $display ("reading file....."); i=0; while (! $feof(file)) begin stat=$fscanf(file,"%d\n",face[i]); i=i+1; end $fclose(file); for(i=0;i<`Lenght;i=i+1) begin $display("face[i]=%d",face[i]); end end and my results is: 3 4 1 4 3 2 Click to expand... thanks
Feb 5, 2018 #2 ads-ee Super Moderator Staff member Joined Sep 10, 2013 Messages 7,944 Helped 1,823 Reputation 3,656 Reaction score 1,808 Trophy points 1,393 Location USA Activity points 60,209 What are you using to run it? I get the following results using both Vivado and Modelsim... Code: reading file..... face[i]= 3 face[i]= 4 face[i]= 14 face[i]= 3 face[i]= 24 face[i]= 5 As this doesn't match your output shown, I suspect you are running the simulation with an older version of the file.
What are you using to run it? I get the following results using both Vivado and Modelsim... Code: reading file..... face[i]= 3 face[i]= 4 face[i]= 14 face[i]= 3 face[i]= 24 face[i]= 5 As this doesn't match your output shown, I suspect you are running the simulation with an older version of the file.
Feb 5, 2018 #3 J jalal.baba Junior Member level 1 Joined Feb 5, 2018 Messages 16 Helped 0 Reputation 0 Reaction score 0 Trophy points 1 Activity points 118 I get wrong result with ModelSim SE-64 10.5 .Which version do you use? I check code with ISE2014 results are true.
I get wrong result with ModelSim SE-64 10.5 .Which version do you use? I check code with ISE2014 results are true.
Feb 5, 2018 #4 ads-ee Super Moderator Staff member Joined Sep 10, 2013 Messages 7,944 Helped 1,823 Reputation 3,656 Reaction score 1,808 Trophy points 1,393 Location USA Activity points 60,209 Modelsim 10.5b and Vivado 2017.2