Hi,
I am working on MCB2300 (with LPC2378 processor). I have written a small function that will read the values into a matrix. But when the control comes to fread it completely hangs up, nothing can be done. Below is the my function which is giving problem
void loadImage(FILE* arq, unsigned char** Matrix){ int i,j; unsigned char tmp; long pos = 51; fseek(arq,0,0); for (i=0; i<300; i++){ for (j=0; j<400; j++){ pos+= 3; fseek(arq,pos,0); fread(&tmp,3,1,arq); Matrix[i][j] = tmp; } } }
Its working fine in GNU C. But when I have tried to use the same code in Keil uVision4, its is not working. Please let me know how to sort this problem
fread, as the name suggests, reads from a file.
Do you have a file system?
The filesystem here is FAT16
Yes, but FAT16 is just a description of how data is stored in the memory device.
But what implementation do you have?
What code is fread() expected to call to perform the task?
And what implementation of that file system do you have to support access to it by functions like fread ?
I am trying to store an image into matrix pixel by pixel. The above code is doing the same. First of all I am opening the image in read mode and passing its file pointer (arq) as reference to loadImage() function. In my code inside the loop, 300 and 400 are corresponds to dimensions of the image (height and width respectively). Initially I thought fread() is not working. But I have realised it is working fine. I have tried the code by changing the height (i.e 300). I have used 1 instead of 300 for i . It worked fine and the values are stored in the Matrix. I have increased the value step by step, it worked fine till the value of i in the code is 8 but later on it stucks from there onwards. I think it has something to do with heap size?? Please help to get rid of this problem
On what basis do you think that?
What have you done to confirm whether it is or not?
"Please help to get rid of this problem"
First, you need to determine what the problem actually is!
The declaration of Matrix looks suspicious:
unsigned char** Matrix
This is a pointer to a pointer (or array of pointers) to unsigned char. You probably wanted this to be a pointer to a two-dimensional array. Can you show us the call to this function and the types of arguments you pass to it?
View all questions in Keil forum