Here I just want to see the content of variable pos ; so what type of format specifier have to used for that ?
#include <stdio.h>
void main() {
FILE *fileptr = fopen("sample.txt", "r+");
fpos_t pos;
int val = fgetpos(fileptr, &pos);
}
fpos_t is defined in the C Standard as :
fpos_twhich is a complete object type other than an array type capable of recording all the information needed to specify uniquely every position within a file.
This type is not necessarily scalar, it could be defined as a struct with multiple members. There is no printf format to output it in a readable fashion. Some systems may need to perform complex tasks to handle text files, not every computer is a PC.
If you are interested in the implementation, you could dump its contents as hex bytes:
#include <stdio.h>
int main(void) {
FILE *fileptr = fopen("sample.txt", "r+");
fpos_t pos;
if (fileptr && fgetpos(fileptr, &pos) == 0) {
printf("contents of pos: ");
for (size_t i = 0; i < sizeof(pos); i++) {
printf("%02X", ((unsigned char *)&pos)[i]);
}
printf("\n");
}
return 0;
}
On many modern systems, you will get 0000000000000000 because a 64 bit integer is sufficient for all information needed to represent the offset into the file, but you should not rely on this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With