ok i solved with this code:
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;
  int c;
  pFile=fopen ("image.jpc","r");
  image=fopen ("bitstream.txt","w");
  if (pFile==NULL) perror ("Error opening file");
  else
  {
    
      c = fgetc(pFile); 
      while (c != EOF)
    {
              ShowByte((char)c, image);
         c = fgetc(pFile); 
    
    } 
        }
    fclose (pFile);
        fclose (image);
  
  return 0;
}

now it works perfectly!
but i have the dual problem now, and so, starting from text, recover the jpc file.
i tried with this code but i get a segmentation fault:
#include <stdio.h>

// text points to 8 bytes string containing 0 and 1 symbols

unsigned char ByteFromText(char* text, FILE * im)
{
    unsigned char result = 0;
    for (int i = 0; i < 8; i++)
    {
        if (text[i] == '1') 
        {
             result &= ( 1 << (7-i) );
         fputc(result, im);
        }
    }
    return result;
}



int main ()
{
  FILE * pFile;
  FILE * image;
  int c;
  pFile=fopen ("bitstream.txt","r");
  image=fopen ("image.jpc","w");
  if (pFile==NULL) perror ("Error opening file");
  else
  {
    
      c = fgetc(pFile); 
      while (c != EOF)
    {
              ByteFromText((char*)c, image);
         c = fgetc(pFile); 
    
    } 
        }
    fclose (pFile);
        fclose (image);

  
  return 0;
}
any suggestions? thanks,
Fra

Last edited by shabbir; 12Oct2009 at 19:45.. Reason: Code blocks