image - File has more bytes than expected...data read from FTDI and written into .bin file -


i trying image data (jpeg) ftdi ft2232 device in windows form using visual c++ clr. whole operation takes place on button click. writing received data .bin file in read operation itself. no of bytes receive around 19k , file has 57k bytes

i not allowed upload images sharing code , wring output getting

    ft_handle fthandle;      ft_status ftstatus;     dword byteswritten;     //dword 32 bit unsigned     dword rxqueuebytes=0;     dword txqueuebytes;     dword buff = 0;     char txbuffer[10];      // contains data write device     char rxbuffer[16000];  // contains data recieved ftdi devide     dword bytesreceived;     dword rxbytes = 0;     dword txbytes = 0;     dword eventdword;       ftstatus = ft_open(0, &fthandle);     if (ftstatus != ft_ok) {         // ft_open failed          return;     }     txbuffer[txbytes++] = 0x30;     txbuffer[txbytes++] = 0x2;     txbuffer[txbytes++] = 0x0;     txbuffer[txbytes++] = 0x42;     txbuffer[txbytes++] = 0x01;      ftstatus = ft_write(fthandle, txbuffer, txbytes, &txbytes);   // data send command             if (ftstatus == ft_ok)              {                 printf(" ft_write ok \n");                 sleep(5000);             }       ft_getqueuestatus(fthandle, &rxqueuebytes);         // read queue                 if (ftstatus == ft_ok)                 {                     printf(" (after wtite)rx_queue_bytes = %i\n", rxqueuebytes);                 }      ft_getstatus(fthandle, &rxqueuebytes, &txqueuebytes, &eventdword);    // read queue             if (ftstatus == ft_ok)              {                 printf(" (after wtite)rx_queue_bytes = %i\n", rxqueuebytes);                 printf(" (after wtite)txqueuebytes = %i\n", txqueuebytes);                 printf(" (after wtite)eventdword = %i\n\n\n\n", eventdword);             }         ftstatus = ft_read(fthandle, rxbuffer, rxqueuebytes, &rxbytes);     if (ftstatus == ft_ok)     {            printf(" ft_read ok\n");         printf(" recieved byte = %c %c %c %c\n", rxbuffer);         ofstream fout("imagedata.bin");  //writing ti file                 if (fout.is_open())                 {                     //file opened here                     printf("file opened successfully!!\n");                      (int = 0; != rxqueuebytes; i++)                     {                         //if (rxbuffer[i]==31)                         fout << rxbuffer[i] << endl; //writing ith character of array in file                     }                     printf("array data saved file imagedata");                 }                 else //file not opened                 {                     printf("file not opened.");                 }      }     else      {         printf(" ft_read failed");     }      getchar();      ft_close(fthandle);      return; 

the output says

rx_queue_bytes = 19283 

the properties of imagedata.bin says has 57892 bytes please explain

opening file in binary mode , removing endl in fout command line solved problem.

 ofstream fout("imagedata.dat", ios::out| ios::binary);         if (fout.is_open())         {             //file opened here             printf("file opened successfully!!\n");              (int = 0; < img_read_index; i++)             {                  fout << point[i] ; //writing ith character of array in file             }             printf("array data saved file imagedata");             fout.close();         }         else //file not opened         {             printf("file not opened.");         }