简体   繁体   中英

format ‘%ld’ expects type ‘long int’, but argument 3 has type “TEST”

Here TEST is a struct pointer. Structure contains integer. What can be the right factor for it? The TEST structure is as follows.I am using gcc as compiler.

     typedef struct TEST_HELP{
                 int value;                
      } *TEST, TEST_NODE;

I'm guessing you have something like:

TEST ptr;
// set ptr to something
ptr->value = 5;
printf( "%ld", ptr ); // expect 5 to be printed

This will not work because printf doesn't know how to print a TEST_HELP structure. You need to print the data within it:

TEST ptr;
// set ptr to something
ptr->value = 5;
printf( "%ld", (long)ptr->value ); // expect 5 to be printed

You should be using %d for int values. %ld is for long values, hence the cast.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM