I am using stat file system in a program and I want to print the device id using
printf("\nst_dev = %s\n",buf.st_dev);
but i am getting error:
warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘__dev_t’ [-Wformat=]
What should b used instead of %s here?
st_dev
is of type dev_t
which is an integer type as per POSIX definition:
dev_t shall be an integer type.
So printing it using %s
certainly wrong. There's no portable way to print it because there's no format specifier defined for it in POSIX. You could use intmax_t
to print it:
printf("\nst_dev = %jd\n", (intmax_t)buf.st_dev);
If intmax_t
isn't available (such as C89 systems) then you could cast it to long
.