Using the C library function fopen, fread the operation of the file, is everyone familiar with the processing method. But a strange and interesting phenomenon has recently been found in the company's actual projects.
The company's project uses VC to write the pre-program, the message sent to the customer character set transcoding operation. A temporary file was used during transcoding. The problem occurs during the temporary file read process. The code is simple:
FILE *FP;//CHENZW:TESTFP = fopen (Utf8file, "R"), if (fp = = NULL) {comlog (__file__,__line__,level_error, "open utf-8 message [%s] Failed \ n ", utf8file); return-3;} char * utf8buff;int Nlen;fseek (fp,0,seek_end); nlen = Ftell (FP);//comlog (__file__,__line__,level_debug, "length nlen[%d]", Nlen); if (Nlen <1) {fclose (FP);//comlog (__file__,__line__,level_error, "utf-8 message [%s] is empty \ n", utf8file); return-4;} Fseek (fp,0,seek_set); utf8buff = (char *) malloc (Nlen + 1); memset (Utf8buff,0,nlen + 1); int rtnlen = Fread (utf8buff,sizeof ( char), NLEN,FP);
Since only one detail message is sent to the customer at a time,
Strange problems when using fread in Windows environment