函数名: stpcpy

功 能: 拷贝一个字符串到另一个

用 法: char *stpcpy(char *destin, char *source);

程序例:

#include <stdio.h>

#include <string.h>

int main(void)

{

   char string[10];

   char *str1 = "abcdefghi";

   stpcpy(string, str1);

   printf("%s\n", string);

   return 0;

}

函数名: strcat

功 能: 字符串拼接函数

用 法: char *strcat(char *destin, char *source);

程序例:

#include <string.h>

#include <stdio.h>

int main(void)

{

   char destination[25];

   char *blank = " ", *c = "C++", *Borland = "Borland";

   strcpy(destination, Borland);

   strcat(destination, blank);

   strcat(destination, c);

   printf("%s\n", destination);

   return 0;

}

函数名: strchr

功 能: 在一个串中查找给定字符的第一个匹配之处\

用 法: char *strchr(char *str, char c);

程序例:

#include <string.h>

#include <stdio.h>

int main(void)

{

    char string[15];

    char *ptr, c = 'r';

    strcpy(string, "This is a string");

    ptr = strchr(string, c);

    if (ptr)

       printf("The character %c is at position: %d\n", c, ptr-string);

    else

       printf("The character was not found\n");

    return 0;

}

函数名: strcmp

功 能: 串比较

用 法: int strcmp(char *str1, char *str2);

看Asic码,str1>str2,返回值 > 0;两串相等,返回0

程序例:

#include <string.h>

#include <stdio.h>

int main(void)

{

    char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";

    int ptr;

    ptr = strcmp(buf2, buf1);

    if (ptr > 0)

       printf("buffer 2 is greater than buffer 1\n");

    else

       printf("buffer 2 is less than buffer 1\n");

    ptr = strcmp(buf2, buf3);

    if (ptr > 0)

       printf("buffer 2 is greater than buffer 3\n");

    else

       printf("buffer 2 is less than buffer 3\n");

    return 0;

}

函数名: strncmpi

功 能: 将一个串中的一部分与另一个串比较, 不管大小写

用 法: int strncmpi(char *str1, char *str2, unsigned maxlen);

程序例:

#include <string.h>

#include <stdio.h>

int main(void)

{

   char *buf1 = "BBB", *buf2 = "bbb";

   int ptr;

   ptr = strcmpi(buf2, buf1);

   if (ptr > 0)

      printf("buffer 2 is greater than buffer 1\n");

   if (ptr < 0)

      printf("buffer 2 is less than buffer 1\n");

   if (ptr == 0)

      printf("buffer 2 equals buffer 1\n");

   return 0;

}

函数名: strcpy

功 能: 串拷贝

用 法: char *strcpy(char *str1, char *str2);

程序例:

#include <stdio.h>

#include <string.h>

int main(void)

{

    char string[10];

    char *str1 = "abcdefghi";

    strcpy(string, str1);

    printf("%s\n", string);

    return 0;

}

函数名: strcspn

功 能: 在串中查找第一个给定字符集内容的段

用 法: int strcspn(char *str1, char *str2);

程序例:

#include <stdio.h>

#include <string.h>

#include <alloc.h>

int main(void)

{

    char *string1 = "1234567890";

    char *string2 = "747DC8";

    int length;

    length = strcspn(string1, string2);

    printf("Character where strings intersect is at position %d\n", length);

    return 0;

}

函数名: strdup

功 能: 将串拷贝到新建的位置处

用 法: char *strdup(char *str);

程序例:

#include <stdio.h>

#include <string.h>

#include <alloc.h>

int main(void)

{

    char *dup_str, *string = "abcde";

    dup_str = strdup(string);

    printf("%s\n", dup_str);

    free(dup_str);

    return 0;

}

函数名: stricmp

功 能: 以大小写不敏感方式比较两个串

用 法: int stricmp(char *str1, char *str2);

程序例:

#include <string.h>

#include <stdio.h>

int main(void)

{

   char *buf1 = "BBB", *buf2 = "bbb";

   int ptr;

   ptr = stricmp(buf2, buf1);

   if (ptr > 0)

      printf("buffer 2 is greater than buffer 1\n");

   if (ptr < 0)

      printf("buffer 2 is less than buffer 1\n");

   if (ptr == 0)

      printf("buffer 2 equals buffer 1\n");

   return 0;

}

函数名: strerror

功 能: 返回指向错误信息字符串的指针

用 法: char *strerror(int errnum);

程序例:

#include <stdio.h>

#include <errno.h>

int main(void)

{

   char *buffer;

   buffer = strerror(errno);

   printf("Error: %s\n", buffer);

   return 0;

}

函数名: strcmpi

功 能: 将一个串与另一个比较, 不管大小写

用 法: int strcmpi(char *str1, char *str2);

程序例:

#include <string.h>

#include <stdio.h>

int main(void)

{

   char *buf1 = "BBB", *buf2 = "bbb";

   int ptr;

   ptr = strcmpi(buf2, buf1);

   if (ptr > 0)

      printf("buffer 2 is greater than buffer 1\n");

   if (ptr < 0)

      printf("buffer 2 is less than buffer 1\n");

   if (ptr == 0)

      printf("buffer 2 equals buffer 1\n");

   return 0;

}

函数名: strncmp

功 能: 串比较

用 法: int strncmp(char *str1, char *str2, int maxlen);

程序例:

#include <string.h>

#include <stdio.h>

int main(void)

{

   char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";

   int ptr;

   ptr = strncmp(buf2,buf1,3);

   if (ptr > 0)

      printf("buffer 2 is greater than buffer 1\n");

   else

      printf("buffer 2 is less than buffer 1\n");

   ptr = strncmp(buf2,buf3,3);

   if (ptr > 0)

      printf("buffer 2 is greater than buffer 3\n");

   else

      printf("buffer 2 is less than buffer 3\n");

   return(0);

}

函数名: strncmpi

功 能: 把串中的一部分与另一串中的一部分比较, 不管大小写

用 法: int strncmpi(char *str1, char *str2);

程序例:

#include <string.h>

#include <stdio.h>

int main(void)

{

   char *buf1 = "BBBccc", *buf2 = "bbbccc";

   int ptr;

   ptr = strncmpi(buf2,buf1,3);

   if (ptr > 0)

      printf("buffer 2 is greater than buffer 1\n");

   if (ptr < 0)

      printf("buffer 2 is less than buffer 1\n");

   if (ptr == 0)

      printf("buffer 2 equals buffer 1\n");

   return 0;

}

函数名: strncpy

功 能: 串拷贝

用 法: char *strncpy(char *destin, char *source, int maxlen);

程序例:

#include <stdio.h>

#include <string.h>

int main(void)

{

   char string[10];

   char *str1 = "abcdefghi";

   strncpy(string, str1, 3);

   string[3] = '\0';

   printf("%s\n", string);

   return 0;

}

函数名: strnicmp

功 能: 不注重大小写地比较两个串

用 法: int strnicmp(char *str1, char *str2, unsigned maxlen);

程序例:

#include <string.h>

#include <stdio.h>

int main(void)

{

   char *buf1 = "BBBccc", *buf2 = "bbbccc";

   int ptr;

   ptr = strnicmp(buf2, buf1, 3);

   if (ptr > 0)

      printf("buffer 2 is greater than buffer 1\n");

   if (ptr < 0)

      printf("buffer 2 is less than buffer 1\n");

   if (ptr == 0)

      printf("buffer 2 equals buffer 1\n");

<

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

Linux C编程--string h函数解析相关推荐

  1. Linux C编程--string.h函数解析

    函数名: stpcpy 功 能: 拷贝一个字符串到另一个 用 法: char *stpcpy(char *destin, char *source); 程序例: #include <stdio. ...

  2. 【Linux系统编程】vfork() 函数详解

    00. 目录 文章目录 00. 目录 01. vfork函数 02. fork和vfork区别 03. 父子进程地址空间 04. 附录 01. vfork函数 函数分析 #include <sy ...

  3. 【Linux系统编程】fork()函数详解

    00. 目录 文章目录 00. 目录 01. 进程创建函数 02. 父子进程结构 03. 父子进程地址空间 04. 附录 01. 进程创建函数 #include <sys/types.h> ...

  4. 基于ESP32的蓝牙鼠标键盘(一)BleKeyboard.h函数解析

    BleKeyboard.h函数解析 关于这个项目 BleKeyboard.h库解析 参数 bleKeyboard.write(c);的参数c 关于这个项目 在GitHub中的项目地址:https:// ...

  5. linux文件重定向 dup,linux之dup和dup2函数解析

    linux之dup和dup2函数解析 linux之dup和dup2函数解析 系统调用dup和dup2能够复制文件描述符.dup返回新的文件文件描述符(没有用的文件描述符最小的编号).dup2可以让用户 ...

  6. 基于ESP32的蓝牙鼠标键盘(二)BleMouse.h函数解析

    BleMouse.h函数解析 例程1--鼠标按钮 案例2--滚动+移动 案例3--每隔两秒向下滚动 BleMouse函数库解析 BleMouse.h是鼠标库. 资料在这里可以找到: https://g ...

  7. string.h函数总结

    string.h函数总结以下的函数使用时 都是入口参数 我们修改相应的入口参数进行试验 1 #ifndef __STRING_NO_EXPORTSusing ::std::size_t;using : ...

  8. string.h函数库详解

    string.h函数总结以下的函数使用时 都是入口参数 我们修改相应的入口参数进行试验 1 #ifndef __STRING_NO_EXPORTSusing ::std::size_t;using : ...

  9. Linux系统编程 46 -lseek函数

    学习笔记 lseek函数 文件偏移 以前有接触到fseek 库函数,lseek和它有点类似. #include <sys/types.h> #include <unistd.h> ...

最新文章

  1. 十大算法,描述+代码+演示+分析+改进(赶紧收藏!)
  2. 暑假周总结七8.26
  3. kvm服务器中心管理,IP KVM如何在公共场所数据中心合理应用
  4. 香农编码二叉树c语言,shannon码的编码实验总结.docx
  5. 安卓手机刷软路由_华为路由AX3 Pro上手测评:用过最方便的路由器,没有之一...
  6. 硬核干货:如果样本量不一一样多,或者不是一一对应关系,如何做差异?相关?...
  7. linux版本的redis bin,redis-4.0.2.tar.gz for centos的linux系统版本下载(安装详细步骤)...
  8. lpc2000 filash utility 程序烧写工具_重点必看 | 取证小程序开发之第四届美亚杯硬盘信息快速解题...
  9. easyui-combobox实现placeholder提示效果
  10. 时间序列分析matlab_平稳时间序列分析之模型识别
  11. .net5 和 .net6 部署到 IIS 完整步骤
  12. LOLBox多玩饭盒Android源码
  13. 崩坏3九游服务器稳定吗,崩坏3:大佬亲身经历告诉你,玩崩坏3到底该不该压等级!...
  14. 微信小程序如何获取地理位置、地图显示,逆地址解析。
  15. 王者荣耀-是用什么编程语言开发的(转)
  16. Error connecting to the target: (Error -6305) PRSC module failed to write to to a register
  17. [附源码]计算机毕业设计JAVAjsp在线视频网站
  18. 毕业设计 - 基于java web的在线考试系统【源码+论文】
  19. 发票样板 html+css
  20. .net android 推送消息,android – FCM(Firebase云消息传递)推送通知与Asp.Net

热门文章

  1. 系统调优一之内存子系统
  2. 图像柔光效果(SoftGlow)的原理及其实现。
  3. VM8不能安装64位操作系统原因解析
  4. 需要注意的小问题------闹的笑话
  5. mysql 学习笔记(二)
  6. 索尼诺基亚持股公司告赢苹果,获300万美元赔偿
  7. iOS最好用的引导页
  8. How to enable javascript in windows server 2008 R2 enterprise
  9. android 学习笔记(八)building system8.5 shell脚本的学习
  10. 将应用程序11M内存占用,降至500K [转]