hi,
i made some progress but i need your help again; i post the code that i wrote but before to do that, i wanted to
verify that the results were good, so i opened some file jpc, but also raw (that is the original image without any header) with an hex editor, where i could see the values of the byte written in hexadecimal format.
Code:
#include <stdio.h>

void ShowByte( char b , FILE * im)
{    
    
    for(int i = 7; i >= 0; --i)
    {
        if ( b & (1 << i) )
        {
              fputc('1', im);
        }
        else
        {
              fputc('0', im);
        }
    
    }
  
}

int main ()
{
  FILE * pFile;
  FILE * image;
  char c;
  pFile=fopen ("image.raw","r");
  image=fopen ("bitstream.txt","w");
  if (pFile==NULL) perror ("Error opening file");
  else
  {

    do {
      c = fgetc (pFile); 
      ShowByte(c, image);
    
    } while (c != EOF);
	    
	fclose (pFile);
     
  }
  return 0;
}
first thing strange (for me): if i declare the variable c as an unsigned char and if in the function ShowByte i declare b as unsigned char, the program never stops (infinite loop?)

secondly: i compare a very big file of 1 MB called image.raw and it seems that the program works, but the file txt generated (4 MB) contains less bytes than the original; the program i wrote cut a very huge amount data at some point that i cannot find.
for example, i create a file with 20 random values with an hex editor, and my program print (correctly) only the first 7 bytes of this file.

finally, if i use in input the file that i have to test, the image.jpc file, my program prints only the first byte!!

please can somebody help me??

Last edited by shabbir; 12Oct2009 at 17:33.. Reason: Code blocks