Reads the values in the TXT document. There is a certain protocol. After reading, the sum is obtained and the average value is calculated.

Source: Internet
Author: User
// Todo: add your control notification handler code herecfile file ("11.txt", cfile: moderead); // create a file, link path, and read method char * pbuf; // define the character pointer to receive the document content, int Len = file. getlength (); // get the object Content Length pbuf = new char [Len + 1]; // pointer space file. read (pbuf, Len); // read the content pbuf [Len] = '\ 0'; // The last character file of the string. close (); // close the file // MessageBox (pbuf); int sum = 0; // sum int COUNT = 0; // data count for (INT I = 0; I <Len; I ++) {If (pbuf [I] = 'A' & pbuf [I + 1] = '+ ') // protocol format {count ++; cstring TMP; TMP + = pbuf [I + 2]; TMP + = pbuf [I + 3]; TMP + = pbuf [I + 4]; TMP + = pbuf [I + 5]; TMP + = pbuf [I + 6]; TMP + = pbuf [I + 7]; the 6 characters after reading the data in the format are int inttmp = atoi (TMP); the string is converted to an integer sum + = inttmp; // sum} cstring s; S. format ("% d", sum/count); // calculate the average value getdlgitem (idc_edit1)-> setwindowtext (s); // display

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.