Discussion:
[c-prog] %hhu
izecksohn@yahoo.com [c-prog]
2018-11-03 00:54:48 UTC
Permalink
Is the following code correct? Or does it has a bug?


#include <stdio.h>


int main ()
{
unsigned char p0, p1;
printf ("Enter 2 values separated by ; ");
scanf ("%hhu;%hhu", &p0, &p1);
printf ("I understood %hhu;%hhu\n", p0, p1);
return 0;

}
Paul Herring pauljherring@gmail.com [c-prog]
2018-11-03 11:28:12 UTC
Permalink
Technically it's correct, but why you'd want to place user input into chars
is potentially questionable.
Post by ***@yahoo.com [c-prog]
Is the following code correct? Or does it has a bug?
#include <stdio.h>
int main ()
{
unsigned char p0, p1;
printf ("Enter 2 values separated by ; ");
scanf ("%hhu;%hhu", &p0, &p1);
printf ("I understood %hhu;%hhu\n", p0, p1);
return 0;
}
--
PJH
Bill Cunningham billcun@suddenlink.net [c-prog]
2018-11-03 15:39:41 UTC
Permalink
Personally I don't use scanf unless there is formatted input. I actualy
use fgets myself directed to stdin. That might be a little unusual. but
it works for me :) Gets can overflow and has I guess, been removed from
the standard.

Bill
Post by Paul Herring ***@gmail.com [c-prog]
Technically it's correct, but why you'd want to place user input into
chars is potentially questionable.
  Is the following code correct? Or does it has a bug?
#include <stdio.h>
int main ()
{
unsigned char p0, p1;
printf ("Enter 2 values separated by ; ");
scanf ("%hhu;%hhu", &p0, &p1);
printf ("I understood %hhu;%hhu\n", p0, p1);
    return 0;
}
--
PJH
Loading...