当前位置: 首页 > news >正文

网站开发进度哪个搜索引擎最好

网站开发进度,哪个搜索引擎最好,wordpress页眉在哪改,湖北企业响应式网站建设价位目录 1.求字符串长度strlen 2.长度不受限制的字符串函数 字符串拷贝strcpy 字符串追加strcat 字符串比较strcmp 3.长度受限制的字符串函数介绍strncpy strncat ​编辑strncmp 4.字符串查找strstr 5.字符串分割strtok 6.错误信息报告 strerror perror 7.字符分类函… 目录 1.求字符串长度strlen 2.长度不受限制的字符串函数 字符串拷贝strcpy 字符串追加strcat 字符串比较strcmp 3.长度受限制的字符串函数介绍strncpy strncat ​编辑strncmp 4.字符串查找strstr 5.字符串分割strtok 6.错误信息报告 strerror perror 7.字符分类函数 8.字符转换函数 9.内存操作函数 memcpy memmove memset memcmp​编辑 1.求字符串长度strlen 函数介绍 字符串已经 \0 作为结束标志strlen函数返回的是在字符串中 \0 前面出现的字符个数不包含 \0 )。参数指向的字符串必须要以 \0 结束。注意函数的返回值为size_t是无符号的 易错   使用示例 int main() {size_t sz strlen(abcd);printf(%u, sz);return 0; } 因为函数的返回值为无符号类型所以对于下面这种代码我们很容易就看错 #includestdio.h #includestring.h int main() {if (strlen(abc) - strlen(abcdef) 0){printf(大于\n);}else{printf(小于\n);}return 0; } 输出结果 正确的比较方法 if (strlen(abc) strlen(abcdef)) strlen的模拟实现 size_t my_strlen(const char* str) {int count 0;while (*str!\0){count;str;}return count; } 2.长度不受限制的字符串函数 字符串拷贝strcpy Copies the C string pointed by source into the array pointed by destination, including the terminating null character (and stopping at that point).源字符串必须以 \0 结束。会将源字符串中的 \0 拷贝到目标空间。目标空间必须足够大以确保能存放源字符串。目标空间必须可变 使用示例 int main() {char arr1[20] { 0 };char arr2[] hello world;strcpy(arr1, arr2);printf(%s, arr1);return 0; } 输出结果  strcpy的模拟实现 char* my_strcpy(char* dest, const char* src) {assert(dest src);char* ret dest;while (*dest *src){}return ret; } 字符串追加strcat Appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a null-character is included at the end of the new string formed by the concatenation of both in destination.源字符串必须以 \0 结束。目标空间必须有足够的大能容纳下源字符串的内容。目标空间必须可修改。字符串自己给自己追加如何 使用示例 int main() {char arr1[20] hello ;char arr2[] world;strcat(arr1, arr2);printf(%s, arr1);return 0; } 输出结果  strcat的模拟实现 char* my_strcat(char* dest, const char* src) {assert(dest src);char* ret dest;while (*dest ! \0)//找到目标空间的\0{dest;}while (*dest *src){}return ret; } 注意字符串不能自己给自己追加  当字符串自己给自己追加时字符串中的\0将会被覆盖导致程序陷入死循环。 字符串比较strcmp This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ or until a terminating null-character is reached.标准规定第一个字符串大于第二个字符串则返回大于0的数字第一个字符串等于第二个字符串则返回0第一个字符串小于第二个字符串则返回小于0的数字 使用示例 int main() {int ret1 strcmp(abcdef, abq);int ret2 strcmp(abc, abc);printf(%d\n, ret1);printf(%d\n, ret2);return 0; } 输出结果  strcmp的模拟实现 int my_strcmp(const char* str1, const char* str2) {assert(str1 str2);while (*str1 *str2){if (*str1 \0){return 0;}}return *str1 - *str2; } 3.长度受限制的字符串函数介绍 strncpy Copies the first num characters of source to destination. If the end of the source C string (which is signaled by a null-character) is found before num characters have been copied, destination is padded with zeros until a total of num characters have been written to it.拷贝num个字符从源字符串到目标空间。如果源字符串的长度小于num则拷贝完源字符串之后在目标的后边追加0直到num个。 使用示例 int main() {char arr1[20] abcdef;char arr2[20] xxxxxxxxxxxxxx;strncpy(arr1, arr2, 3);printf(%s\n, arr1);return 0; } 输出结果  strncat Appends the first num characters of source to destination, plus a terminating null-character.If the length of the C string in source is less than num, only the content up to the terminating null-character is copied. 使用示例 int main() {char arr1[20] hello ;char arr2[20] worldxxx;strncat(arr1, arr2, 5);printf(%s\n, arr1);return 0; } 输出结果  strncmp 比较到出现另个字符不一样或者一个字符串结束或者num个字符全部比较完。 使用示例 int main() {char arr1[20] abc;char arr2[20] abcdef;char arr3[20] aba;printf(%d\n, strncmp(arr1, arr2, 3));printf(%d\n, strncmp(arr1, arr2, 4));printf(%d\n, strncmp(arr1, arr3, 5));return 0; } 输出结果  4.字符串查找strstr strstr函数是在字符串str1中查找是否含有字符串str2如果存在返回str2在str1中第一次出现的地址否则返回NULL。 使用示例 int main() {char arr1[] abcdefabcdef;char arr2[] def;char* ret strstr(arr1, arr2);if(ret!NULL){printf(%s\n, ret);}return 0; } 输出结果  strstr的模拟实现 这里使用的是BF算法来实现 char* my_strstr(char* str1, char* str2) {char* cp str1;char* s1 cp;char* s2 str2;while (*cp){s1 cp;s2 str2;while (*s1 *s2 *s1 *s2){s1;s2;}if (*s2 \0)return cp;cp;}return NULL; } 5.字符串分割strtok sep参数是个字符串定义了用作分隔符的字符集合第一个参数指定一个字符串它包含了0个或者多个由sep字符串中一个或者多个分隔符分割的标 记。strtok函数找到str中的下一个标记并将其用 \0 结尾返回一个指向这个标记的指针。注 strtok函数会改变被操作的字符串所以在使用strtok函数切分的字符串一般都是临时拷贝的内容并且可修改。strtok函数的第一个参数不为 NULL 函数将找到str中第一个标记strtok函数将保存它在字符串中的位置。strtok函数的第一个参数为 NULL 函数将在同一个字符串中被保存的位置开始查找下一个标记。如果字符串中不存在更多的标记则返回 NULL 指针。 使用示例1 int main() {char arr[] 123qq.com;char sep[] .;char copy[20];strcpy(copy, arr);char* pc strtok(copy, sep);while (pc){puts(pc);pc strtok(NULL, sep);}return 0; } 使用示例2 int main() {char arr[] 123qq.com;char sep[] .;char copy[20];strcpy(copy, arr);char* ret NULL;for (ret strtok(copy, sep); ret ! NULL; ret strtok(NULL, sep)){printf(%s\n, ret);}return 0; } 输出结果  6.错误信息报告 strerror 返回错误码所对应的错误信息。 库函数在执行的时候发生了错误会将错误码存放在errno这个全局变量中。errno是C语言提供的一个全局变量。 下面代码是将错误码0~9所对应的错误信息给打印出来 int main() {int i 0;for (int i 0; i 10; i){printf(%d:%s\n, i, strerror(i));}return 0; } 当然这里展示的仅仅是一小部分。 下面演示一下当我们进行文件操作是打开文件失败后查找打开失败的原因 int main() {FILE* pf fopen(data.txt, r);if (pf NULL){printf(%s\n, strerror(errno));}return 0; } 程序输出了“ No such file or directory ”的错误提示意思是没有要打开的文件。 perror perror(str) 用来将上一个函数发生错误的原因输出到标准设备(stderr)。参数 str 所指的字符串会先打印出后面再加上错误原因字符串。此错误原因依照全局变量errno的值来决定要输出的字符串。 使用示例 int main() {FILE* pf fopen(data.txt, r);if (pf NULL){printf(%s\n, strerror(errno));perror(fopen);}return 0; } 输出结果 7.字符分类函数 8.字符转换函数 下面代码的功能是输入一串字符将字符串中的小写字母转成大写大写字母转成小写 int main() {char arr[30] { 0 };gets(arr);char* p arr;while (*p){if (isupper(*p)){*p tolower(*p);}else if (islower(*p)){*p toupper(*p);}*p;}puts(arr); } 9.内存操作函数 memcpy 函数memcpy从source的位置开始向后复制num个字节的数据到destination的内存位置。这个函数在遇到 \0 的时候并不会停下来。如果source和destination有任何的重叠复制的结果都是未定义的。 可以拷贝任意类型的数据字符串整形数组结构体数据类型…… 使用示例 int main() {int arr1[] { 1,2,3,4,5,6,7,8,9,10 };int arr2[20] { 0 };//将arr1的内容拷贝到arr2中memcpy(arr2, arr1, 40);for (int i 0; i 20; i){printf(%d , arr2[i]);}return 0; } 输出结果 memcpy的模拟实现 void* my_memcpy(void* dest, void* src, size_t num) {assert(dest src);void* ret dest;while (num--){*(char*)dest *(char*)src;dest (char*)dest 1;src (char*)src 1;}return ret; } 注意下面这种写法编译器会报错 在代码中使用了(char*)dest和(char*)src来更新指针的位置。然而这种写法是不正确的因为后缀递增操作符的优先级高于类型转换操作符(char*)所以实际上你只是在转换指针类型后递增了一个临时变量而没有更新指针本身的值。 注意mencpy 函数是用来处理不会重叠的内存拷贝当我们拷贝两个相同的字符串是可以结果与预期的会不相同 int main() {int arr1[] { 1,2,3,4,5,6,7,8,9,10 };my_memcpy(arr12, arr1, 32);for (int i 0; i 10; i){printf(%d , arr1[i]);}printf(\n);return 0; } 对于上面的代码我们的预期结果是这样的 实际输出的结果却是如下 如果要拷贝重叠的内存我们就要使用下面这个函数了 memmove 和memcpy的差别就是memmove函数处理的源内存块和目标内存块是可以重叠的。如果源空间和目标空间出现重叠就得使用memmove函数处理。 使用示例 int main() {int arr1[] { 1,2,3,4,5,6,7,8,9,10 };memmove(arr12, arr1, 32);for (int i 0; i 10; i){printf(%d , arr1[i]);}printf(\n);return 0; } 输出结果 memmove的模拟实现 不同于memcpy,mommove的拷贝需要分情况 void* my_memmove(void* dest, const void* src, size_t num) {assert(dest src);void* ret dest;if (dest src){//从前向后拷贝while (num--){*(char*)dest *(char*)src;dest (char*)dest 1;src (char*)src 1;}}else{printf(从后向前拷贝\n);//从后向前拷贝while (num--){*((char*)dest num) *((char*)src num);}}return ret; } memset memset是一个初始化函数作用是将某一块内存中的全部设置为指定的值。 prr 指向要填充的内存块。value 是要被设置的值。num 是要被设置该值的字符数。返回类型是一个指向存储区s的指针。 使用示例1 int main() {char arr[] hello world;memset(arr 1, x, 4);printf(%s\n, arr);return 0; } 上面代码的作用是将的arr数组的第2个元素到第5个元素的值设置成‘x,输出结果 使用示例2 int main() {int arr[10] { 0 };memset(arr, 1, 10);return 0; } memcmp 比较从ptr1和ptr2指针开始的num个字节 返回值如下 使用示例 int main() {int arr1[] { 1,2,1,4,5,6 };int arr2[] { 1,2,257 };int ret memcmp(arr1, arr2, 9);printf(%d\n, ret);return 0; } 对于上面的代码可以借助编译器的调试来查看 arr1 和 arr2 的内存 可以看出arr1和arr2的前9个字节是相同的而我们比较的是前9个字节因此输出结果应该是0。
http://www.pierceye.com/news/926706/

相关文章:

  • 国外开源 企业网站建设网站经营范围
  • 做棋牌游戏网站云南软件开发
  • 广州做网站哪家好福州微信网站开发
  • 网站建设:做网站是不是很麻烦
  • 网站开发合同官司python能开发app吗
  • 福建建设厅网站简历表格 个人简历手机版
  • 重庆企业网站定制开发公司重庆城乡建设子网站
  • 网站地图怎么做html公司文化的建设对个人的意义
  • html网站模板免费下载台州网站制作 外贸
  • 有关建筑网站建设方案案例平台网站建设哪家有
  • 网站域名跳转是怎么做的空间一个数据库可以做几个网站
  • asp网站幻灯片不显示微商刚起步怎么找客源
  • 婚恋网站翻译可以做吗科技局网站建设方案
  • 长沙哪里学网站建设德阳做网站的公司
  • 制作短链接网站做抽奖网站违法吗
  • 网站备案每年审吗做网站做推广
  • 网站名称 规则个人网页模板背景
  • 网站制作方案策划简历网站建设咨询有客诚信网站建设咨询
  • 格尔木市住房和城乡建设局网站能看全景的地图软件
  • 一站式网站建设与运营wordpress后台代码修改
  • 企业品牌类网站有哪些做网站建设的公司是什么类型
  • 自己制作的网站怎么做分页2022建站市场
  • 网贷审核网站怎么做wordpress 文章列表页
  • 搬家网站建设公司西安是哪个省市
  • php 网站 整合 数据库智能建站系统个人网站
  • 福田区罗湖区宝安区龙华区seo上首页排名
  • 网站建设业务员提成企业网站 需求
  • 做淘宝客网站 首选霍常亮国外网页设计
  • 天津小型企业网站设计方案网页升级访问每天自动更新 下载
  • 好的学习网站打广告壹搜网站建设优化排名