I am trying to parse the information in a TIFF file. To do this, I have an array of unsigned bytes.
Code:
FILE * tiffFile;
int i,j;
GLubyte (* fields)[12];
unsigned short numOfFields=0;
long index;
...
//get number of fields
...
fields = malloc(numOfFields*12*sizeof(GLubyte));
for(i=0;i<numOfFields;i++) {
for(j=0;j<12;j++) {
fread(&(fields[i][j]),1,1,tiffFile);
}
}
index = findTag(0x100,fields,numOfFields);
The findTag function is as follows.
Code:
long findTag(short tag, GLubyte **fields, int numOfFields){
int i,found=0;
for(i=0;(i<numOfFields) && !found;i++){
if (tag == fields[i][0]*256 + fields[i][1])
found = 1;
}
printf("Index of tag: %x is: %d",tag,i);
return i;
}
For a reason I do not understand, I get a warning "passing arg 2 of 'findTag' from incompatible pointer type". And while executing the findTag function, I get a Bus Error, usually (but not always) when i=1.
I checked in the debugger, fields in the main function, or in findTag points to the same memory address. And I don't understand why it works perfectly when I fill it up in the main, but not when I want to read from it in findTag.
I tried to use a fixed size for the array, but I get the exact same problem.