当前位置:网站首页>strncat() strncmp()
strncat() strncmp()
2022-07-23 23:14:00 【InfoQ】
strncat() - 連接字符串(受長度限制)
char *strncat(char *dest, const char *src, size_t n)strncat()函數代碼示例
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main(void)
{
char str1[20];
char str2[20];
strcpy(str1, "Cyuyan");
strcpy(str2, "yyds");
printf(strncat(str1, str2, 5));//追加字符串!
return 0;
}
printf(strncat(str1, str2, 4));

strncat()源程序實現
char * __cdecl strncat (
char * front,
const char * back,
size_t count
)
{
char *start = front;
while (*front++)
;
front--;
while (count--)
if (!(*front++ = *back++))
return(start);
*front = '\0';
return(start);
}
strncmp() - 比較字符串(受長度限制)
int strncmp(const char *str1, const char *str2, size_t nstrncmp()函數代碼示例
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main(void)
{
char str1[20];
char str2[20];
strcpy(str1, "Cyuyan");
strcpy(str2, "Cyuyanyyds");
printf("%d", strncmp(str1, str2, 6));
return 0;
}strncat()源程序實現
int __cdecl strncmp
(
const char *first,
const char *last,
size_t count
)
{
size_t x = 0;
if (!count)
{
return 0;
}
/*
* This explicit guard needed to deal correctly with boundary
* cases: strings shorter than 4 bytes and strings longer than
* UINT_MAX-4 bytes .
*/
if( count >= 4 )
{
/* unroll by four */
for (; x < count-4; x+=4)
{
first+=4;
last +=4;
if (*(first-4) == 0 || *(first-4) != *(last-4))
{
return(*(unsigned char *)(first-4) - *(unsigned char *)(last-4));
}
if (*(first-3) == 0 || *(first-3) != *(last-3))
{
return(*(unsigned char *)(first-3) - *(unsigned char *)(last-3));
}
if (*(first-2) == 0 || *(first-2) != *(last-2))
{
return(*(unsigned char *)(first-2) - *(unsigned char *)(last-2));
}
if (*(first-1) == 0 || *(first-1) != *(last-1))
{
return(*(unsigned char *)(first-1) - *(unsigned char *)(last-1));
}
}
}
/* residual loop */
for (; x < count; x++)
{
if (*first == 0 || *first != *last)
{
return(*(unsigned char *)first - *(unsigned char *)last);
}
first+=1;
last+=1;
}
return 0;
}
边栏推荐
- VIM common shortcut keys
- Can Intel NUC replace the host_ It's finally perfect! The latest Intel NUC Mini host comes online
- Introduction and project development of MVVM and mvvmlight (I)
- 【音视频技术】视频质量评价 MSU VQMT & Netflix vmaf
- Array - 977. Square of ordered array
- 2、 Digital logic functional unit
- Crazy God redis notes 10
- The Minesweeper game
- Basic operations of AutoCAD
- AutoCAD advanced operation
猜你喜欢

The canfd/can interface offline burning operation instructions of h7-tool have been updated (2022-07-12)

Tap series article 9 | application development accelerator

USB to can device in nucleic acid extractor high performance USB interface can card

FL Studio 20.9 update Chinese version host Daw digital audio workstation
![[web vulnerability exploration] SQL injection vulnerability](/img/94/dc84d7790d5a1823e4b73d513e86be.png)
[web vulnerability exploration] SQL injection vulnerability

系列文章|云原生时代下微服务架构进阶之路 - 微服务拆分的最佳实践

USB转CAN设备在核酸提取仪 高性能USB接口CAN卡

【音视频技术】视频质量评价 MSU VQMT & Netflix vmaf

Smart IOT source code with configuration IOT source code industrial IOT source code: support sensor analysis services, real-time data collection and remote control

疑似未系安全带 林志颖伤势相对稳定
随机推荐
关于电脑端同步到手机端数据
[laser principle and Application-8]: EMC design of laser circuit
Video Number strengthens the fight against vulgar content: the content that violates public order and good customs must be eliminated
[in depth study of 4g/5g/6g topic -40]: urllc-11 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -5-5g QoS principle and Architecture: slicing, PDU s
D1-H 开发板——哪吒 开发入门
Three network modes of VMware virtual machine
Debian | Can’t locate Debian/Debhelper/Sequence/germinate. pm in @INC
Raspberry pie SSH login
After reading this article, thoroughly understand grpc!
ES6箭頭函數的使用
Programming in the novel [serial 16] the moon bends in the yuan universe
The Minesweeper game
疑似未系安全带 林志颖伤势相对稳定
【Unity3D日常BUG】Unity3D解决“找不到类型或命名空间名称“XXX”(您是否缺少using指令或程序集引用?)”等问题
Can Intel NUC replace the host_ It's finally perfect! The latest Intel NUC Mini host comes online
As a developer, you have to know the three performance testing tools JMeter, API and jmh user guide
Array -- 209. Subarray with the smallest length
TAP 系列文章7 | 易于管理的流水线配置
Is it safe to open a VIP stock account on your mobile phone?
[nuxt 3] (IX) server routing