当前位置:网站首页>Strncat () strncmp ()
Strncat () strncmp ()
2022-07-23 23:14:00 【InfoQ】
strncat() - Chaîne de connexion(Limité par la longueur)
char *strncat(char *dest, const char *src, size_t n)strncat()Exemple de code de fonction
#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));//Ajouter une chaîne!
return 0;
}
printf(strncat(str1, str2, 4));

strncat() Mise en œuvre du programme source
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() - Comparer les chaînes(Limité par la longueur)
int strncmp(const char *str1, const char *str2, size_t nstrncmp()Exemple de code de fonction
#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() Mise en œuvre du programme source
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;
}
边栏推荐
- Leetcode: palindrome number
- Can Intel NUC replace the host_ It's finally perfect! The latest Intel NUC Mini host comes online
- Grey prediction (matlab)
- USB to can device in nucleic acid extractor high performance USB interface can card
- The role of physical layer, link layer, network layer, transport layer and application layer of tcp/ip model of internet protocol stack
- Internet协议栈 TCP/IP模型 物理层、链路层、网络层、传输层、应用层的作用
- Finding all paths between two points in a directed graph
- 礪夏行動|源啟數字化:既有模式,還是開源創新?
- [problem handling] merge made by the 'ort' strategy
- At the forefront of the times, Huawei aims at the wind and sea of digital finance
猜你喜欢

Diabetes genetic risk testing challenge advanced

Notes on network segment CIDR

Interviewer: if the order is not paid within 30 minutes after it is generated, it will be automatically cancelled. How to realize it?

Diabetes genetic risk testing challenge baseline

unity visual studio2019升级到2022版本(扔掉盗版红渣)

在openEuler社区开源的Embedded SIG,来聊聊它的多 OS 混合部署框架

TAP 系列文章9 | 应用开发加速器

Classification model - logistic regression, Fisher linear discriminant (SPSS)

Sword finger offer II 115. reconstruction sequence

How to reasonably estimate the size of thread pool
随机推荐
Tap series article 5 | cloud native build service
1000个Okaleido Tiger首发上线Binance NFT,引发抢购热潮
Data sorting and usage before torchvision.datasets.imagefolder
Wechat applet implements a global event bus by itself
Array -- 209. Subarray with the smallest length
Extract any page number in PDF file with itextpdf
Programming in the novel [serial 17] the moon bends in the yuan universe
AutoCAD advanced operation
Mongodb - Introduction to the usage of logical operators not, and, or, nor in query statements
糖尿病遗传风险检测挑战赛Baseline
二,数字逻辑功能单元
Tap series article 4 | backstage based tap developer portal
TAP 系列文章4 | 基于 Backstage 的 TAP 开发者门户
Galaxy Securities opens an account online. Is it safe to open an account on your mobile phone
Leetcode: palindrome number
Learning MySQL is enough
Interface test
D1-h development board - Introduction to Nezha development
Tap series article 8 | tap Learning Center - learn through hands-on tutorials
2、 Digital logic functional unit