scanf a byte then print it out?

Posted by Sarah on Stack Overflow See other posts from Stack Overflow or by Sarah
Published on 2012-11-12T22:47:24Z Indexed on 2012/11/12 23:00 UTC
Read the original article Hit count: 202

Filed under:
|
|

I've searched around to see if I can find this answer but I can't seem to (please let me know if I'm wrong).

I am trying to use scanf to read in a byte, an unsigned int and a char in one .c file and I am trying to access this byte in a different .c file and print it out.

(I have already checked to make sure I have included all the appropriate parameters everywhere) But I keep getting errors.

The warnings are:

database.c: In function ‘addCitizen’:
database.c:23:2: warning: format ‘%hhu’ expects argument of type ‘int’, but argument 2 has type ‘byte *’ [-Wformat]
database.c:24:2: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘int *’ [-Wformat]
database.c:25:2: warning: format ‘%c’ expects argument of type ‘int’, but argument 2 has type ‘char *’ [-Wformat]

where I'm scanf'ing:

// Request loop
while (count-- != 0)
{
    while (1){

        // Get values from the user
        int error = scanf ("%79s %hhu %u %c", tname,
            &tdist, &tyear, &tgender);  
        addCitizen(db, tname, &tdist, &tyear, &tgender);

where I'm printing:

void addCitizen(Database *db, char *tname, byte *tdist, int *tyear, char *tgender){
   //needs to find the right place in memory to put this stuff and then put it there
   printf("\nName is: %79s\n", tname);
   printf("District is: %hhu\n", tdist);
   printf("Year of birth is: %u\n", tyear);
   printf("Gender is:%c\n", tgender);

I'm not sure where I'm going wrong?

© Stack Overflow or respective owner

Related posts about byte

Related posts about printf