Hi guys, i really need help here. I must write a program in c that reads a file .RAW that it contains photos in sequential order, every photo has a head-board of 4 bytes. (0xff 0xd8 oxff 0xe0 or 0xe1) and that way I can identify the beginning of the photo and the size.
dont know if i must read the file in binary form or not, and i do not understand whath this storing in the dynamic vector
The files in this folder will have to be separated and with the extension .JPG which it will allow his visualization. In turn, these will have to have a name that goes from 0.jpg up to [Number of photos in the file].jpg.
It will have guard in a dynamic vector the size of each one of the photos. It is to say that
The size of the vector will be exactly the quantity of the existing photos in the file to
To recover.
This is what I did till now
#include <stdio.h>
#include <stdlib.h>
void load(FILE *archivo, unsigned char *vector, int n);
void findHeader (unsigned char *vector, int n);
int main()
{
unsigned char *character;
int cont=0;
int nBytes;
char c;
FILE* file = fopen("fotos.RAW", "r");
if(archivo != NULL)
{
fseek(archivo, 0, SEEK_END); o
nBytes = ftell(file); // size in bytes
rewind(file);
printf("The size of file is: %d Kbytes\n", nBytes/1024 ) ;
while( ( c = fgetc( archivo ) ) != EOF )
cont++;
}
else
{
printf("error!\n");
}
rewind(file);
cargar(file, character, cont);
findHeader(character, cont);
fclose(file);
getch();
return 0;
}
void load(FILE *archivo,unsigned char *vector, int n)
{
int i;
char c;
vector = (unsigned char*) malloc (sizeof(unsigned char)*n+1);
if (vector == NULL)
printf("wrong operation\n");
else
{
while( ( c = fgetc( file ) ) != EOF )
{
for (i=0; i <= n; i++)
{
vector[i] = c;
printf("0x%x", vector[i]); // to control what is saving in the array
getch();
}
}
}
}
void findHeader (unsigned char *vector, int n)
{
int band=0;;
int i;
for(i=0; i <=n; i++)
{
if ((vector[i] == 0xff ) && (vector[i+1] == 0xd8) && (vector[i+2] == 0xff) && (vector[i+3] == 0xe0))
band++;
else
{
if ((vector[i] == 0xff) && (vector[i+1] == 0xd8) && (vector[i+2] == 0xff) && (vector[i+3] == 0xe1))
band++;
}
}
printf("Band show up %d times\n", band); //to control how many pics are
}