int send_duff(char *to, char *from,int count1 ,int count)
{
int ret = 0;
int n = (count + 7) / 8;
from = from + count - 1;
to = to + count1 - 1;
switch(count % 8) {
case 0: do { if(*to-- == *from--) ret++;
case 7: if(*to-- == *from--) ret++;
case 6: if(*to-- == *from--) ret++;
case 5: if(*to-- == *from--) ret++;
case 4: if(*to-- == *from--) ret++;
case 3: if(*to-- == *from--) ret++;
case 2: if(*to-- == *from--) ret++;
case 1: if(*to-- == *from--) ret++;
} while(--n > 0);
}
return ret == count;
}
int main(void)
{
const char* s = "123machaodfuuh";
const char* t = "uh";
printf("%u\n",
send_duff( (char*)s,(char*)t,strlen(s),strlen(t) )
);
return 0;
}
这个程序是使用duff设备实现的,输出为1(表示t出现在s的末尾,否则为0)
判断字符串t是否出现在字符串s的末尾
最新推荐文章于 2022-02-23 14:50:46 发布