B
Beginner
Hi,
I am trying to use the LIBTIFF library to read some metadata (IPTC)
stored in the file. The library provides a simply interface to the data
via a TAG reference . My problem is that I am sooo green with C that I
am not sure how to handle the data. Below is what I have written so
far. It compiles (Linux GCC 3.4.2), runs and outputs the text I expect
but then it seg faults.
I have no real sanity checks on because I don't know how to convert the
data in the pointer into character text. Can anyone offer any advice on
how to de-reference the data correctly (cast hasn't worked for me
either) and possibly some way to check that the data coming through is
of the type char?
TIA.
=================
include <stdio.h>
include <tiffio.h>
main()
int i, j;
uint16 count;
void *data;
char iptc_data[600];
TIFF* tif = TIFFOpen("test.tif", "r");
if (tif == NULL) {
printf("Failed to open file\n");
exit(8);
}
if (TIFFGetField(tif, TIFFTAG_RICHTIFFIPTC, &count, &data) == 0) {
printf("No IPTC Tag found\n");
exit(8);
}
printf("Size of IPTC Tag is %d bytes. %s.\n", count , &data);
for ( i = 0; i < count; ++i) {
strcat(iptc_data, &data);
}
printf("%s\n", iptc_data);
TIFFClose(tif);
return 0;
}
=====================
I am trying to use the LIBTIFF library to read some metadata (IPTC)
stored in the file. The library provides a simply interface to the data
via a TAG reference . My problem is that I am sooo green with C that I
am not sure how to handle the data. Below is what I have written so
far. It compiles (Linux GCC 3.4.2), runs and outputs the text I expect
but then it seg faults.
I have no real sanity checks on because I don't know how to convert the
data in the pointer into character text. Can anyone offer any advice on
how to de-reference the data correctly (cast hasn't worked for me
either) and possibly some way to check that the data coming through is
of the type char?
TIA.
=================
include <stdio.h>
include <tiffio.h>
main()
int i, j;
uint16 count;
void *data;
char iptc_data[600];
TIFF* tif = TIFFOpen("test.tif", "r");
if (tif == NULL) {
printf("Failed to open file\n");
exit(8);
}
if (TIFFGetField(tif, TIFFTAG_RICHTIFFIPTC, &count, &data) == 0) {
printf("No IPTC Tag found\n");
exit(8);
}
printf("Size of IPTC Tag is %d bytes. %s.\n", count , &data);
for ( i = 0; i < count; ++i) {
strcat(iptc_data, &data);
}
printf("%s\n", iptc_data);
TIFFClose(tif);
return 0;
}
=====================