str data -> jpeg

#include <stdio.h>
#include <fcntl.h>  
#include <io.h>  
#include <string.h>  
#include <sys/types.h>    
#include <sys/stat.h>

#define u8 unsigned char

u8 str2int(u8 buf0 , u8 buf1){
    u8 tmp  , tmp1 , tmp2 ;

    if( buf0>='0' && buf0 <= '9'){
        tmp1 = buf0 - '0' ;
    }else if(buf0>= 'a' && buf0 <= 'z'){
        tmp1 = buf0 - 'a' + 10;
    }

    if( buf1>= '0' && buf1 <= '9'){
        tmp2 = buf1 - '0' ;
    }else if(buf1>='a' && buf1 <= 'z'){
        tmp2 = buf1 - 'a' + 10;
    }

    //printf("tmp1:%d - tmp2:%d \n" , tmp1 , tmp2) ;
    tmp = tmp1*16 + tmp2 ;

    return tmp ;
}


int main()
{
    int size = 0 , index=0;//用于判断是否读取结束的

    u8 buf[100] = {0} , tmp , tmp1;//字符类型只有1字节,可以将各个类型的拿出来

    char buffer , buffer1 ;
    FILE *p_src = NULL, *p_dest = NULL;

    //打开第一个文件,即已存在的文件
    p_src=fopen("src.txt", "rb");//不知道是文本还是二进制,所以统一用二进制
    if(!p_src) {
        return 0;
    }
    //打开第二个文件,不存在的文件
    p_dest = fopen("dst.jpg", "wb");//以二进制打开,不能用a方式
    if(!p_dest) {
        fclose(p_src);//当打开目标文件出错时,原始文件已经打开了,这里会直接结束程序,所以应该结束原始文件
        p_src = NULL;
        return 0;
    }
    while(1) {
        size = fread(&buffer, 1 , 1 , p_src);//一次存储100字节整数倍,导致原目大小不一致,所以在存的时候用size
        if( buffer == 0x20 || buffer == 0x0d || buffer==0x0a){
            continue ;
        }
        size = fread(&buffer1, 1 , 1 , p_src);

        //printf(" - 0x%c%c - \n" , buffer , buffer1) ;
        tmp = (u8)str2int(buffer , buffer1) ;
        //printf(" > 0x%02x < \n" , tmp) ;

        fwrite(&tmp, sizeof(char), 1, p_dest);
        index++ ;

        if(tmp1 == 0xff && tmp == 0xd9){
             printf("jpeg end ! \n") ;
            break ;
        }
        tmp1 = tmp ;
    }

    fclose(p_src);
    p_src = NULL;
    fclose(p_dest);
    p_dest = NULL;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
void S1mmeSession::CtEncodeKqi(S1MMEKQI* kqi, S1APNode* p_node, uint8_t worker_id) { MsgCommonInfo& common = p_node->GetCommonInfo(); SPUserInfo& sp_user_info = p_node->GetUserInfo(); //获取 buf TlvEncoder* p_encoder_cur = g_p_encoder_[worker_id]; YdCDR_T* p_dst_data = (YdCDR_T*)malloc(sizeof(YdCDR_T)); if (p_dst_data == NULL) { return; } p_dst_data->not_associate = 0; if ((common.not_associate & 0x03) == 0x03) p_dst_data->not_associate = 1; p_encoder_cur->Set(p_dst_data->cdr_data,kMaxOneCdrBufLen); uint64_t imsi = sp_user_info->GetIMSI(); if(common.eci == 0) { common.eci = sp_user_info->GetEci(); } uint16_t tmp_enbid = common.tac;//>>8; //uint32_t tmp_enbid = (common.eci >> 8)&0xfffff; char xdrid_str[32]={0}; #ifdef OPEN_NEW_HUISU convert_xdrid_to_string(xdrid_str, kqi->xdrid, s_xdr_id_len); #else #ifdef OPENCTPR g4sigtran::pr::ProcBlock* p_blk = kqi->binary_block_in_xdr_.GetBlock(); p_blk->SerializeXid(xdrid_str, sizeof(xdrid_str)); #else uint64_t subcdrid = g_ct_xdr_id.GetXid(); //reverse subend; if(::is_open_reverse) { SetReverseSubend(p_node, subcdrid); } #ifdef ONE_THIRD_YUNNAN_MRO g_ct_xdr_id.Serialize((uint8_t*)xdrid_str, s_xdr_id_len, imsi); #else g_ct_xdr_id.Serialize((uint8_t*)xdrid_str, s_xdr_id_len); #endif #endif #endif struct timespec start_time = kqi->request_time_, end_time = kqi->response_time_; if (kqi->request_time_.tv_sec == 0) { if (!(kqi->response_time_.tv_sec == 0)) { start_time = kqi->response_time_; } else if (!(kqi->complete_time_.tv_sec == 0)) { start_time = kqi->complete_time_; } }要求:在S1mmeSession::CtEncodeKqi函数后面新加一个函数,来维护一组key、value的关系。 key为:imsi value为:imsi、imei、common.eci、common.tac、last_time 当imsi相同时,以最后一条记录的value内容为准进行保存;imsi不同时直接插入。请用C++实现该功能,需要用到哈希的知识点
06-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值