sscanf issues

  • Thread starter Kenneth Brun Nielsen
  • Start date
K

Kenneth Brun Nielsen

Guest
Hi all,

I have two questions related to the $sscanf function.

First, I read input stimuli (among others) from a file. If 5 bit
values are read, I should do one thing, and if only 4 bit values are
read, something else should be done. E.g.

while (!$feof(fd))
begin
r = $fgets(textline,fd);
if ($sscanf(textline, "%1b %1b %1b %1b %1b
\n",SSread,SCKread,MOSIread,DIread,DINread) > 0)
begin
$display("FULL VECTOR READ");
end
else if ($sscanf(textline, "%1b %1b %1b %1b
\n",SSread,SCKread,MOSIread,DI1read) > 0)
begin
$display("HALF VECTOR READ");
end
else if ($sscanf(textline, "%s\n",subtext) > 0)
begin
$display("LINE NOT RECOGNIZED");
end
end

The problem is, that both input lines consisting of four and five bit
values seems to satisfy the first 'if' conditional. The same thing
happends, if I switch them around.

Any suggestions to how I can differentiate between four and five input
values?

Best regards,
Kenneth
 
On Oct 29, 7:11 am, Kenneth Brun Nielsen
<kenneth.brun.niel...@googlemail.com> wrote:
Any suggestions to how I can differentiate between four and five input
values?
I don't have the LRM in front of me, but if memory serves, $sscanf
returns the number of values assigned (this is definitely true in C),
so try something like this:

integer count;

count = $sscanf(textline, "%1b %1b %1b %1b %1b
\n",SSread,SCKread,MOSIread,DIread,DINread);
if (count == 5)
$display("FULL VECTOR READ");
else if (count == 4)
$display("HALF VECTOR READ");
....

-cb
 

Welcome to EDABoard.com

Sponsor

Back
Top