If i read a picture with fread and imediately write all readed data into a file the original file (picture) differs completely from newly written file. As written in the topic these two files differ completely. I do compare it with hexdump. Would there be please some one kind and help me? The same problem i have when i read code from FCGI_getchar. The original file and the new file differ in hexdump comparison.
#include "fcgi_stdio.h"
#include <stdlib.h>
#include <string.h>
int main(void)
{
    int count = 0;
//  char stdinchar;
    char *requestmethod;
    FILE *fptr; 
    FILE *fptr1;
    char *buffer;
    long size;
    while(FCGI_Accept() >= 0) {
        printf("Content-type: text/html\r\n"
        "\r\n"
        "<title>FastCGI Hello!</title>"
        "<h1>FastCGI Hello!</h1>"
        "<p>das ist ein test</p>"
        "Request number %d running on host <i>%s</i>\n",
        ++count, getenv("SERVER_NAME")); 
    
        printf("<form action=\"fcgid-script.fcgi\" method=\"post\" enctype=\"multipart/form-data\">");
        printf("    <label>Wählen Sie eine Datei.");
        printf("        <input name=\"datei\" type=\"file\">"); 
        printf("    </label>");  
        printf("    <button>… und ab geht die Post!</button>");
        printf("</form>\n\n");
    
/*      while ( stdinchar != 0 ) { */
/*      while (stdinchar) { */
        requestmethod = getenv("REQUEST_METHOD");
/*      fptr = fopen("/var/www/hiawatha/picture.jpg","wb"); */
        if (strcmp( requestmethod, "POST") == 0) {
    
/*          printf("<i>content-length:%s</i><i>content-type:%s</i>\n",
            getenv("CONTENT_LENGTH"), getenv("CONTENT_TYPE"));      
            while (FCGI_getchar() != EOF ) { 
*/  
    
            fptr = fopen("/home/josef/Pictures/1925.jpg", "rb");
            fptr1 = fopen("/home/josef/Pictures/test123.jpg", "w+b");
            fseek (fptr , 0 , SEEK_END);
            size = ftell(fptr);
            rewind(fptr);   
//          while (!feof(fptr)) {
            fread(buffer, 1, size, fptr);
            fwrite(buffer, 1, size, fptr1);
            fclose(fptr);
            fclose(fptr1);
//      }
    
//          stdinchar = (char) FCGI_getchar(); 
        
//          printf("%c", stdinchar); 
/*          fprintf(fptr,"%d",stdinchar); */
/*          fwrite(&stdinchar, 1, sizeof(stdinchar), fptr); */
        
    
/*          printf("<p>das ist ein test</>"); */
//      }
/*      fclose(fptr);  */   
    
        } 
    }    
    return 0;
}
 
    