Strange problems when using fread in Windows environment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.