sel

#include <iostream>


using namespace std;


int main()
{
    FILE * fp = NULL:
    FILE * fp2=NULL:
    if( !(fp = fopen("./wang.pcap","r+")))
    {
        cout << "open file error!" << endl;
        return -1;
    }
    if( !(fp2 = fopen("./wang.txt","w+")))
    {
        cout << "create file error!" << endl;
        return -1;
    }
    char sBuf[512]={0}; //read a line
    char sTmp[512]={0}; //cache result
    char *pBeg=NULL:
    char *pEnd=NULL;


    while(fgets(sBuf,sizeof(sBuf),fp))
    {
        //new line
        pBeg=NULL:
        memset(sTmp,0x00,sizeof(sTmp));
        //find SELECT
        if( (pBeg=strstr(sBuf,"SELECT")) || (pBeg=strstr(sBuf,"select")) ||
           (pBeg=strstr(sBuf,"LECT")) || (pBeg=strstr(sBuf,"lect")) )
        {
            if(pEnd=strchar(pBeg,';'))
            {
                if(*pBeg == 'L')
                {
                    strncpy(sTmp,"SE",2);
                    strncpy(sTmp+2,pBeg,pEnd-pBeg);
                }
                if(*pBeg == 'l')
                {
                    strncpy(sTmp,"se",2);
                    strncpy(sTmp+2,pBeg,pEnd-pBeg);
                }
                else
                {
                     strncpy(sTmp,pBeg,pEnd-pBeg);
                }


                //check
                if(!strstr(sTmp,"from") && !strstr(sTmp,"FROM"))
                {
                    continue;
                }
                //save one result
                fprintf(fp2,"%s\n",sTmp);
            }
            else
            {
                // ; is in next line?
                pEnd=sBuf+strlen(sBuf)-1;
                strncpy(sTmp,pBeg,pEnd-pBeg);
                memset(sBuf,0x00,sizeof(sBuf));
                fgets(sBuf,sizeof(sBuf),fp);
                if(pEnd=strchar(sBuf,';'))
                {


                }
                else
                {
                    memset(sTmp,0x00,sizeof(sTmp));
                   continue;
                }
            }
        }
        //find not
        else
        {


        }
    }




    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值