⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asc2c.cpp

📁 特殊行业的asc码换算以及检错。很好用的小工具。你能从中学到很多处理文件以及字符串转换的东西。
💻 CPP
字号:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
using namespace std;
ofstream fout;

string result[20];
string comp[20];
string path;
char x[101];
string com="";
int ct=0,ct1=0;
bool ff=0,sf=0,hf=0;
int lg=0;
void D2S(string a);
void SOP();
void SCL();
void CT();
int main(int argc, char *argv[])
{
    fout.open("c:/result.txt");
    cout<<"Type in the path of the file: and add '#' before & after the String.\nAdd '@' the line before your expect results\n:";
    getline(cin,path);
    //cout<<path.c_str()<<endl;
    if(path[0]=='"')
    {
     path.erase(0,1);
     path[path.length()-1]='\0';
    }
    char ch;
    string a="";
    fstream fin;
    fin.open(path.c_str());
    while(!fin.eof())
    {
       ch=fin.get();
       if(ch=='\#')
       {
                   if(!hf)hf=1;
                   else 
                   {SOP();SCL();}
       }
       
       

       if(ch=='H'&&hf)
       {
         ch=fin.get();
         if('\''==ch)
         {
          
           ch=fin.get();
           a+=ch;
           ch=fin.get();
           a+=ch;
           ch=fin.get();
           a+=ch;
           ch=fin.get();
           a+=ch;
           
           D2S(a);
           a="";
         }
       }
       if(ch=='\@')
       {
       fin.getline(x,100);
         while(fin.getline(x,100))
         {
          comp[ct1]=x;
          //cout<<comp[ct1]<<endl;
          ct1++;
          
         }
       }
      
                        
    }
    //cout<<a<<endl;
    CT();
    //D2S();
    //SOP();
    fin.close();
    fout.close();
      
    //ShellExecute(NULL,   "open",   "c:/result.txt",   NULL,   NULL,   SW_SHOW);
    
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
void D2S(string a)
{
     char temp;
     if(!ff)
       {
          sscanf(a.substr(2,2).c_str(),"%x",&lg);
          //cout<<"length:"<<lg<<endl;
          ff=1;    
       }
     else{
          sscanf(a.substr(2,2).c_str(),"%x",&temp);
     com+=temp;
     }
     sscanf(a.substr(0,2).c_str(),"%x",&temp);
     com+=temp;
}
void SOP()
{
     int i;
     i=com.length();
     //com.erase(0,1);
     if(com[i-1]==0)
     {             
                 com[i-1]='\0';
                i-=1;
                
     }
     if(lg==i)
     {
                           
     cout<<"length:"<<lg<<endl;
     fout<<"length:"<<lg<<endl;
     //cout<<i<<endl;
     }
     else 
     {
          cout<<"length is mismatch"<<endl;
          fout<<"length is mismatch"<<endl;
     }
     cout<<com<<endl;
     fout<<com<<endl;
     result[ct]=com;
     ct++;
}
void SCL()
{
     cout<<"================================================"<<endl;
     fout<<"================================================"<<endl;
     com="";
     ff=0;
     lg=0;
     sf=0;
     hf=0;
}
void CT()
{
     
     for(int i=0;i<ct;i++)
     {
      if(strcmp(result[i].c_str(),comp[i].c_str())!=0)
      {
       fout<<i<<"  :What's wrong?\n"<<result[i]<<"\n"<<comp[i]<<"\n"<<endl;
       cout<<i<<"  :What's wrong?\n"<<result[i]<<"\n"<<comp[i]<<"\n"<<endl;
      }
      else
      {
          cout<<i<<"  :"<<result[i]<<" is correct \n"<<endl;
          fout<<i<<"  :"<<result[i]<<" is correct \n"<<endl;
      }
     }
     printf("All the result put into c:\\result.txt\n");
     system("notepad.exe c:/result.txt");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -