當前位置:編程學習大全網 - 網站源碼 - 用c語言實現算術編碼和解碼

用c語言實現算術編碼和解碼

Turbo c 2.0編譯通過

#include?<stdio.h>

#include?<stdlib.h>

#include?<string.h>

#define?LENGTH?100 /*字符串(編碼前或編碼後)的最大長度*/

/*編碼*/

voidencode(char*strsource);

/*解碼*/

voiddecode(char*strcode);

void?main()?

{?

char?code[LENGTH]="BILL?GATES";?

encode(code);

printf("\nencoded?string?is:%s\n",code);

decode(code);

printf("\ndecoded?string?is:%s\n",code);

getch();

}

void?encode(char?*strsource){

char?*p=strsource,tmp[LENGTH]={'\0'},buffer[3];?

while(*p){

itoa(*p++,buffer,10);

strcat(tmp,"%");

strcat(tmp,buffer);?

}?

strcpy(strsource,tmp);

}

void?decode(char?*strcode){

int?i=0;

char?*p,*s=strcode,tmp[LENGTH]={'\0'};

char?*cSplit="%";

p=strtok(s,cSplit);

while(p)

{

tmp[i++]?=?atoi(p);

p=strtok(NULL,cSplit);

}

strcpy(strcode,tmp);

}

  • 上一篇:請問學CNC電腦鑼加工要先入門哪些3D軟件?
  • 下一篇:我移植的freemodbus為什麽壹直收不到數據
  • copyright 2024編程學習大全網