添加lzw压缩算法

This commit is contained in:
ranchuan
2023-12-02 11:52:15 +08:00
parent 9e46a19283
commit a556d0a141
31 changed files with 1593 additions and 2 deletions

74
other/mystring.c Normal file
View File

@@ -0,0 +1,74 @@
/*
*
* 把整数字符串传化为int,直到遇到非数字字符
*
*/
static int str_ainttoi(const char *s)
{
int ret=0;
int sig=1;
if(*s=='-'){
s++;
sig=-1;
}
while(*s)
{
if(*s>='0'&&*s<='9')
{
ret*=10;
ret+=*s-'0';
}
else return ret;
s++;
}
return ret*sig;
}
int str_ahextoi(const char *s)
{
int ret=0;
while(*s)
{
if(*s>='0'&&*s<='9')
{
ret*=16;
ret+=*s-'0';
}
else if(*s>='a'&&*s<='f')
{
ret*=16;
ret+=*s-'a'+10;
}
else if(*s>='A'&&*s<='F')
{
ret*=16;
ret+=*s-'A'+10;
}
else return ret;
s++;
}
return ret;
}
int str_atoi(const char *s)
{
if(s[0]=='0'&&((s[1]=='x')||(s[1]=='X'))){
return str_ahextoi(&s[2]);
}else{
return str_ainttoi(s);
}
}