⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strlcpycat.c

📁 klibc精简化的c程序库
💻 C
字号:
#include <stdio.h>#include <stddef.h>#include <stdlib.h>#include <string.h>int main(void){	char temp[8];	size_t len;	printf("strlcpy:\n");	len = strlcpy(temp, "123", sizeof(temp));	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "123") != 0)		goto error;	len = strlcpy(temp, "", sizeof(temp));	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "") != 0)		goto error;	len = strlcpy(temp, "1234567890", sizeof(temp));	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "1234567") != 0)		goto error;	len = strlcpy(temp, "123", 1);	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "") != 0)		goto error;	len = strlcpy(temp, "1234567890", 1);	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "") != 0)		goto error;	len = strlcpy(temp, "123", 0);	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "") != 0)		goto error;	len = strlcpy(temp, "1234567890", 0);	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "") != 0)		goto error;	len = strlcpy(temp, "1234567", sizeof(temp));	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "1234567") != 0)		goto error;	len = strlcpy(temp, "12345678", sizeof(temp));	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "1234567") != 0)		goto error;	printf("\n");	printf("strlcat:\n");	strcpy(temp, "");	len = strlcat(temp, "123", sizeof(temp));	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "123") != 0)		goto error;	strcpy(temp, "ABC");	len = strlcat(temp, "", sizeof(temp));	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "ABC") != 0)		goto error;	strcpy(temp, "");	len = strlcat(temp, "", sizeof(temp));	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "") != 0)		goto error;	strcpy(temp, "ABC");	len = strlcat(temp, "123", sizeof(temp));	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "ABC123") != 0)		goto error;	strcpy(temp, "ABC");	len = strlcat(temp, "1234567890", sizeof(temp));	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "ABC1234") != 0)		goto error;	strcpy(temp, "ABC");	len = strlcat(temp, "123", 5);	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "ABC1") != 0)		goto error;	strcpy(temp, "ABC");	len = strlcat(temp, "123", 1);	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "ABC") != 0)		goto error;	strcpy(temp, "ABC");	len = strlcat(temp, "123", 0);	printf("'%s'len:%zu strlen:%zu\n", temp, len, strlen(temp));	if (strcmp(temp, "ABC") != 0)		goto error;	exit(0);error:	printf("unexpected result\n");	exit(1);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -