vc++6.0 to convert the text format to save

Source: Internet
Author: User

The first step:

Building MFC Engineering

Step two: Layout The interface

Step three: Edit button

Here is the code implementation that selects the reconciliation text and transforms it

voidcreorderdatadlg::onbutton1 () {Charsum_text[255], tmp[ +]; Longi; FILE*fp_s, *fp_t; Charsrcfilename[255], tagfilename[255]; Charerr_msg[255], szreadbuff[1024x768], szresultbuff[1024x768]; //Todo:add your control notification handler code hereCFileDialog Dlg (TRUE,//true to create an open file dialog box, False to create a Save File dialog box        "",//the default type of open fileNull//The default open file nameofn_hidereadonly | ofn_overwriteprompt,//Open a read-only file        "*(*.*)|*.*||"); //"text file (*.txt) |*.txt| All files (*. *) |*.*| |");    if(dlg. DoModal () = =IDOK) {CString M_filepath= Dlg. GetPathName ();////////remove file pathCString m_path; M_path=m_filepath;//Place the path of the file into M_pathmemset (srcfilename,0x00,sizeof(srcfilename)); strcpy (srcfilename, M_path. GetBuffer (255));     UpdateData (FALSE); }    Else        return; Memset (tagfilename,0x00,sizeof(tagfilename)); memcpy (tagfilename, Srcfilename+strlen (srcfilename)-8,8 ); strcat (tagfilename,". txt"); //AfxMessageBox (tagfilename);memset (err_msg,0x00,sizeof(err_msg)); fp_s= fopen (srcfilename,"R"); if(fp_s = =NULL) {sprintf (err_msg,"file[%s] OPEN failed!", srcfilename); return; } fp_t= fopen (tagfilename,"W"); if(fp_t = =NULL) {sprintf (err_msg,"file[%s] OPEN failed!", tagfilename); return; } I=0;  while( !feof (FP_S)) {memset (szreadbuff,0x00,sizeof(szreadbuff)); Memset (szresultbuff,0x00,sizeof(szresultbuff)); Fgets (szreadbuff, +, fp_s); if(feof (FP_S)) break;    Str_alltrim (szreadbuff); //AfxMessageBox (szreadbuff);        if(szreadbuff[0]<0x30|| szreadbuff[0] >0x39 )        {            Continue; }        //processing of liquidated documents into standard        /*Trading Date*/memset (tmp,0x00,sizeof(tmp)); if(!str_find_field (szreadbuff, FLAG, one, Tmp))            {strcat (szresultbuff, tmp); strcat (szresultbuff,"    " ); }                /*Trading Hours*/memset (tmp,0x00,sizeof(tmp)); if(!str_find_field (szreadbuff, FLAG, a, Tmp)) {            Charvalue_tmp[ a]; Memset (value_tmp,0x00,sizeof(value_tmp)); memcpy (value_tmp, tmp,6 );            strcat (szresultbuff, value_tmp); strcat (szresultbuff,"    " ); }                /*Terminal number*/memset (tmp,0x00,sizeof(tmp)); if(!str_find_field (szreadbuff, FLAG,3, Tmp))            {strcat (szresultbuff, tmp); strcat (szresultbuff,"    " ); }        /*Card number--special Handling*/        Chartmp_str[ +]; Memset (tmp,0x00,sizeof(tmp)); Memset (tmp_str,0x00,sizeof(tmp_str)); if(!str_find_field (szreadbuff, FLAG,1, Tmp)) {sprintf (tmp_str,"%-19.19s", tmp);            strcat (szresultbuff, tmp_str); strcat (szresultbuff,"    " ); }                        /*Amount*/memset (tmp,0x00,sizeof(tmp)); if(!str_find_field (szreadbuff, FLAG,7, Tmp))            {strcat (szresultbuff, tmp); strcat (szresultbuff,"    " ); }                /*Reference Number*/memset (tmp,0x00,sizeof(tmp)); if(!str_find_field (szreadbuff, FLAG,Ten, Tmp))            {strcat (szresultbuff, tmp); strcat (szresultbuff,"    " ); }                /*type of transaction*/memset (tmp,0x00,sizeof(tmp)); if(!str_find_field (szreadbuff, FLAG,6, Tmp)) {                        if(STRCMP (tmp,"0103") {strcat (szresultbuff,"return" ); strcat (szresultbuff,"    " ); }            Else{strcat (szresultbuff,"Consumer" ); strcat (szresultbuff,"    " ); }        }                /*issuing Bank*/strcat (szresultbuff,"UnionPay" ); strcat (szresultbuff,"\ n");        Fputs (szresultbuff, fp_t); I++; Memset (sum_text,0x00,sizeof(sum_text)); sprintf (sum_text,"processing%d Records", i); GetDlgItem (idc_static)-SetWindowText (sum_text);            UpdateData (FALSE);    } fclose (fp_s);    Fclose (fp_t); sprintf (sum_text,"%d pen processed, processing completed", i); GetDlgItem (idc_static)-SetWindowText (sum_text);    UpdateData (FALSE); return;}

Where the Str_find_fild function is implemented by definition

Class Creorderdatadlg:public CDialog

{

Construction

Public

Creorderdatadlg (cwnd* pparent = NULL);//standard constructor

int change_file (char *filein, Char *fileout);

int Str_find_field (char *buf, char *delimer, int fld_no, Char *field);

Specifically implemented as

int Creorderdatadlg::str_find_field (  char *buf, char *delimer, int fld_no, char *field) {char*p1, *p2, ch;inti;p1 = bu F;for (i=0;i<fld_no-1;i++) {p1 = strstr (p1, delimer), If (!p1)/* not found */return-1;p1 + = strlen (delimer);} P2 = strstr (p1, delimer), if (!p2) strcpy (field, p1), else{ch = *P2;*P2 = 0;strcpy (field, p1); *p2 = ch;} Str_alltrim (field); return 0;}

  

void Creorderdatadlg::onbutton1 () {char sum_text[255], tmp[512];long i; FILE *fp_s, *fp_t;char srcfilename[255], tagfilename[255];char err_msg[255], szreadbuff[1024], szResultBuff[1024];
Todo:add your control notification handler code Herecfiledialog DLG (true,//true is the Create open file dialog box, False creates a save file dialog "",// Default Open File type null,//file name opened by default Ofn_hidereadonly | Ofn_overwriteprompt,//open read-only file "* (* *) |*.*| |"); /"text file (*.txt) |*.txt| All files (*. *) |*.*| |"); If (dlg. DoModal () ==idok) {CString m_filepath = Dlg. GetPathName ();////////take out the file path CString m_path; M_path=m_filepath;//the path of the file into M_path memset (srcfilename, 0x00, sizeof (srcfilename)), strcpy (srcfilename, m_path. GetBuffer (255));     UpdateData (FALSE); }elsereturn;
memset (tagfilename, 0x00, sizeof (tagfilename)), memcpy (tagfilename, srcfilename+strlen (srcfilename)-8, 8); strcat (tagfilename, ". txt"); AfxMessageBox (tagfilename);
memset (err_msg, 0x00, sizeof (err_msg)), fp_s = fopen (srcfilename, "r"), if (fp_s = = NULL) {sprintf (err_msg, "file[%s" OPE N failed! ", srcfilename); return;}
fp_t = fopen (tagfilename, "w"), if (fp_t = = NULL) {sprintf (err_msg, "file[%s] OPEN failed!", tagfilename); return;}
I=0;while (!feof (fp_s)) {memset (szreadbuff, 0x00, sizeof (szreadbuff)), memset (szresultbuff, 0x00, sizeof (szresultbuff ); fgets (szreadbuff, fp_s); if (feof (fp_s)) break; Str_alltrim (szreadbuff);//afxmessagebox (szreadbuff); If (szreadbuff[0]< 0x30 | | szreadbuff[0] >0x39) {continue;}
Processed into a standard liquidation document/* transaction date */memset (tmp, 0x00, sizeof (tmp)), if (!str_find_field (szreadbuff, FLAG, one, tmp)) {strcat (szresult Buff, tmp); strcat (szresultbuff, "");}        /* Trading Time */memset (tmp, 0x00, sizeof (tmp)); If (!str_find_field (szreadbuff, FLAG, n, tmp)) {char value_tmp[12];memset (value_tmp,0x00, sizeof (value_tmp)); memcpy        (value_tmp, tmp, 6); strcat (szresultbuff, value_tmp); strcat (szresultbuff, "");}        /* Terminal number */memset (tmp, 0x00, sizeof (tmp)); If (!str_find_field (szreadbuff, FLAG, 3, tmp)) {strcat (szresultbuff, tmp); strcat (szresultbuff, "");}
/* card number--special handling */char tmp_str[40];memset (tmp, 0x00, sizeof), memset (tmp_str, 0x00, sizeof (tmp_str));    &NB Sp   If (!str_find_field ( szreadbuff, FLAG, 1, tmp  )) {sprintf (tmp_str, "%-19.19s", tmp); strcat (SZRESULTB uff, tmp_str); strcat (szresultbuff, "");} /* amount */memset (tmp, 0x00, sizeof);        If (!str_find_field (szreadbuff, FLAG, 7, tmp)) {strca T (szresultbuff, tmp); strcat (szresultbuff, "");} /* Reference number */memset (tmp, 0x00, sizeof), if (!str_find_field ( szreadbuff, FLAG, tmp  )) {strcat (szresultbuf f, tmp); strcat (szresultbuff, "");} /* transaction type */memset (tmp, 0x00, sizeof (tmp)), if (!str_find_field ( szreadbuff, FLAG, 6, tmp  )) {if (strcmp (tmp, "0 103 ")) {strcat (szresultbuff," return "); strcat (szresultbuff," ");} Else{strcat (szresultbuff, "consumption"); strcat (szresultbuff, "");}} /* issuing bank */strcat (szresultbuff, "unionpay"), strcat (szresultbuff, "\ n");        fputs (szresultbuff, fp_t); i+ +;memsET (sum_text, 0x00, sizeof (sum_text)); sprintf (sum_text, "processing%d records", i);
GetDlgItem (idc_static)->setwindowtext (sum_text); UpdateData (FALSE);}

Fclose (fp_s); fclose (fp_t); sprintf (sum_text, "processed%d, processing completed", i); GetDlgItem (idc_static)->setwindowtext (sum_text); UpdateData (FALSE);
Return
}

vc++6.0 to convert the text format to save

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.