下面是自我测试
| "hello word"字符串,我只要"word"怎么实现 | “hello wang"与"hello li”,我想要比较这两个字符串前面4个字符是不是一样的,怎么弄 | 我想把"hello word"的一段"hello"复制到另一个字符数组怎么弄 | 我想把"hello wang"的"hello"替换成"hi"怎么实现 | 字符串连接函数 | str2的前N个字符连接到str1后面 | 比较两个字符串的ASCLL码大小 | 将str2复制到str1里面 | 将str2前N个字符复制到str1里面 | 返回str1与str2第一个匹配的字符的下标 | 返回字符串长度 | 比较str2是不是str1的子字符串
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Str_Text1()
{
char *Str = "hello word!";
char* Frist_Show;
Frist_Show = memchr(Str, 'o', strlen(Str));
printf("字符%c后面的字符串是%s",Frist_Show[0],Frist_Show);
}
void Str_Text2()
{
char* Name1 = "yqj";
char* Name2 = "zyj";
int Sign = memcmp(Name1, Name2, 1);
if (Sign >0)
{
printf("yqj的姓Y > zyj的姓Z");
}
else
{
printf("yqj的姓Y < zyj的姓Z");
}
}
void Str_Text3()
{
char Name1[10] = {NULL};
char* Name2 = "zyj";
memcpy(Name1, Name2, 2);
printf("姓氏:%s", Name1);
}
void Str_Text4()
{
char Name1[10];
char* Name2 = "zyj";
memcpy(Name1, Name2, strlen(Name2));
for (size_t i = 0; i < strlen(Name2); i++)
{
printf("%c", Name1[i]);
}
}
void Str_Text5()
{
char Name1[10] = "zyj";
memset(Name1, 'A', 2);
puts(Name1);
}
void Str_Text6()
{
char Name1[20] = "zyj";
char Name2[20] = "yqj";
strcat(Name1, Name2);
puts(Name1);
}
void Str_Text7()
{
char Name1[20] = "zyj";
char Name2[20] = "yqj";
strncat(Name1, Name2,4);
puts(Name1);
}
void Str_Text8()
{
char Name1[20] = "hello word";
char* p;
p = strchr(Name1, ' ');
printf("'%c'后续的字符串是%s",p[0],p);
}
void Str_Text9()
{
char Name1[20] = "hello word";
char Name2[20] = "Hello word";
if (strcmp(Name1,Name2) == 1 )
{
printf("hello word > Hello word");
}
else
{
printf("hello word < Hello word");
}
}
void Str_Text10()
{
char Name1[20] = "hello word";
char Name2[20] = "Hello word";
if (strcoll(Name1, Name2) == 1)
{
printf("hello word > Hello word");
}
else
{
printf("hello word < Hello word");
}
}
void Str_Text11()
{
char Name[20];
char Name1[20] = "hello word";
strcpy(Name, Name1);
printf("%s", Name);
}
void Str_Text12()
{
char Name[20] = {NULL};
char Name1[20] = "hello word";
strncpy(Name, Name1,5);
for (size_t i = 0; i < strlen(Name); i++)
{
printf("%c", Name[i]);
}
}
void Str_Text13()
{
char Name[20] = "Hello word";
char Name1[20] = "hello word";
int Sign = strcspn(Name, Name1);
printf("第一个匹配到的字符下标是:%d --> 字符是:%c" ,Sign,Name[Sign]);
}
void Str_Text14()
{
FILE* fp = NULL;
fp = fopen("xxx.txt", "r");
if (fp == NULL)
{
printf("ERROR:%s", strerror(errno));
}
}
void Str_Text15()
{
char* Engs = "zyj";
printf("字符串长度:%d", strlen(Engs));
}
void Str_Text16()
{
char* Engs1 = "abcdf4567";
char* Engs2 = "lj4g";
char *Eng;
Eng = strpbrk(Engs1, Engs2);
printf("匹配到的字符是%c", Eng[0]);
}
void Str_Text17()
{
char* Engs = "www.baidu.com";
char* p;
p = strrchr(Engs,'.');
printf("'%c'最后一次出现的位置后的字符串是:%s", p[0], p);
}
void Str_Text18()
{
char* Engs1 = "HELLO WORD";
char* Engs2 = "HELLO Word!";
size_t Sub;
Sub = strspn(Engs1, Engs2);
printf("第一个未匹配到的字符是第%d个字符,对应的字符是%c",Sub,Engs1[Sub-1]);
}
void Str_Text19()
{
char* Engs1 = "hello the word!";
char* Engs2 = "then";
char* p;
p = strstr(Engs1,Engs2);
printf("%s", p);
}
void Str_Text20()
{
char Engs1[20]= "www.baidu.com";
char Engs2[2] = ".";
char* p = NULL;
p = strtok(Engs1, Engs2);
while (p!=NULL)
{
printf("\n%s", p);
p = strtok(NULL, Engs2);
}
}
void STRING_TEXT()
{
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-53718.html