2、字符串的复制
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
char dest[128] = {};
char src[128] = "hello";
/*dest = src;*/
strcpy(dest, src);
printf("dest : %s\n", dest);
/*dest = "hoa are you";*/
strcpy(dest, "how are you");
printf("dest : %s\n", dest);
//dest = "how a re you"
//src = "hel lo" how alo
strcpy(dest + 20, src + 3);
printf("dest : %s\n", dest);
printf("dest : %s\n", dest + 20);
bzero(dest, sizeof(dest));
printf("dest : %s\n", dest);
strncpy(dest, src + 2, 2);
printf("dest : %s\n", dest);
return 0;
}
====================================================
4、字符串的连接strcat
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
char s1[128] = "hello";
char s2[128] = "world";
/*strcat(s1, s2);*/
/*strcat(s2, s1);*/
strncat(s2, s1, 2);
printf("s1 : %s\n", s1);
printf("s2 : %s\n", s2);
return 0;
}
==============================================================
5、字符串的比较
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
char s1[128] = "make";
char s2[128] = "make";
printf("strcmp(make, mask) = %d\n", strcmp("make", "mask"));
printf("strcmp(make, make) = %d\n", strcmp("make", "make"));
printf("strcmp(mask, make) = %d\n", strcmp("mask", "make"));
printf("strcmp(makee, make) = %d\n", strcmp("makee", "make"));
printf("strncmp(make, mask, 2) = %d\n", strncmp("make", "mask", 2));
/*
* int a = 10, b = 10;
*
* if (s1 == s2)
* {
* printf("there two number are some!\n");
* }
* else
* {
* printf("there two number are diff!\n");
* }
*/
return 0;
}
====================================================
7、字符串的查找
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
printf("strchr(hello, l) = %s\n", strchr("hello", 'l'));
printf("strrchr(hello, l) = %s\n", strrchr("hello", 'l'));
printf("strchr(hello, l) = %s\n", strchr("hello", 'L'));
printf("==================\n");
printf("strstr(hello, lo) = %s\n", strstr("hello", "lo"));
printf("strstr(hello, lo) = %s\n", strstr("hello", "Lo"));
printf("strstr(hello, lo) = %s\n", strstr("hello", "l"));
printf("strcasestr(hello, Lo) = %s\n", strcasestr("hello", "Lo"));
/*printf("strstr(hello, lo) = %s\n", strstr("hello", 'l'));*/
return 0;
}