#include <stdio.h>

#include <assert.h>

char *strcpy(char *strDest,const char *strSrc) //复制字符串

{

assert((strDest!=NULL)&&(strSrc!=NULL));

char *address = strDest;

while((*strDest++=*strSrc++)!='\0')

NULL; //空语句

return address;

}

int strcmp(const char *s1,const char * s2)  //比较字符串

{

assert(s1!=NULL&&s2!=NULL);

while(*s1&&*s2&&*s1==*s2)

{

s1++;

s2++;

}

return (*s1-*s2);

}

char *strcat(char *strDes, const char *strSrc)//连接字符串

{

assert((strDes!=NULL)&&(strSrc!=NULL));

char *address = strDes;

while(*strDes!='\0')  //将原字符串指针移到最后一个字符

strDes++;

while((*strDes++=*strSrc++)!='\0')

NULL;

return address;

}

int strlen(const char *str) //求字符串长度

{

assert(str!=NULL);

int len = 0;

while(*str++!='\0')

{

len++;

}

return len;

}

int main(int argc, char* argv[])

{

char a[10];

strcpy(a,"hello world");

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

char s1[]="abcd";

char s2[]="abcd";

int res = strcmp(s1,s2);

printf("%d\n",res);

char b[]="hello";

char c[]="world";

char d[20];

strcpy(d,b);

strcat(d,c);

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

int len = strlen(a);

printf("%d\n",len);

return 0;

}

常见的C字符串处理函数的源代码的更多相关文章

  1. JavaScript中常见的字符串操作函数及用法

    JavaScript中常见的字符串操作函数及用法 最近几次参加前端实习生招聘的笔试,发现很多笔试题都会考到字符串的处理,比方说去哪儿网笔试题.淘宝的笔试题等.如果你经常参加笔试或者也是一个过来人,相信 ...

  2. Python:常见操作字符串的函数

    Python中提供了很多操作字符串的函数: string = "hello, my dear python!" string.capitalize() #将字符串中的第一个字母大写 ...

  3. C 常见字符串操作函数

    头文件 <string.h> 1. char *strstr(const char *str1, const char *str2);      判断str2是否为str1的子串  //s ...

  4. c/c++ 常见字符串处理函数总结 strlen/sizeof strcpy/memcpy/strncpy strcat/strncat strcmp/strncmp sprintf/sscanf strtok/split/getline atoi/atof/atol

    这里总结工作中经常用到的一些c/c++的字符串处理方法,标黑的是使用频率较高的   1.strlen函数:计算目标字符串长度,    格式:strlen(字符指针指向区域) 注意1:①不包含字符串结束 ...

  5. JS字符串格式化函数 string.format

    原生JS写的仿C#的字符串format函数,在此基础上又增加了便于JS使用的字面量对象参数. 参照C#中的规则,调用的时候会检测字符串格式,如果字符串格式不规范,或者传入的参数为null或undefi ...

  6. SQL注入的字符串连接函数

    在select数据时,我们往往需要将数据进行连接后进行回显.很多的时候想将多个数据或者多行数据进行输出的时候,需要使用字符串连接函数.在sqli中,常见的字符串连接函数有concat(),group_ ...

  7. SQLServer学习笔记<>sql的范围内查找,sql数据类型,字符串处理函数

    sql的范围内查找 (1)between.....and用法 通常情况下我们查找一个在某固定区域内的所有记录,可以采用>=,<=来写sql语句,例如:查找订单价格在1000到2000之间的 ...

  8. (实用篇)多个PHP中文字符串截取函数

    字符串截取是一个非常常见的编程任务,而往往带中文的字符串截取会经常用到.虽然不难,但是自己写函数实现又耗费时间,这里介绍一个比较好用的字符串截取函数,能够胜任基本的需求了 <?php funct ...

  9. Sql注入中连接字符串常用函数

    在select数据时,我们往往需要将数据进行连接后进行回显.很多的时候想将多个数据或者多行数据进行输出的时候,需要使用字符串连接函数.在sqli中,常见的字符串连接函数有concat(),group_ ...

随机推荐

  1. jQuery第三课 点击按钮 弹出层div效果

    jQuery 事件方法 事件方法会触发匹配元素的事件,或将函数绑定到所有匹配元素的某个事件. 触发实例: $("button#demo").click() 上面的例子将触发 id= ...

  2. 详解:(cron , crontab , anacron)

    导读: 人类把时间做了切割,想象一条笔直的线永远向前,本来这条直线上什么都没有,但是人类根据时间的长短(单位)在这条直线上做了密密麻麻的标记(世纪-年-月-日-时-分-秒-纳秒......),通过这样 ...

  3. 虚拟集群LVS及DR模式搭建笔记

    LVS(虚拟集群Linux Virtual Server) LVS-NAT:地址转换,数据包来回都要经过NAT转换,所以Director Server(即LVS服务器)将成为系统瓶颈.使用NAT模式将 ...

  4. Python3+Gurobi使用教程(一)

    Gurobi使用教程 1.Gurobi使用的一般框架 from gurobipy import * try: m=Model('modelname') except GurobiError: prin ...

  5. 微信小程序的开启授权,当单机取消授权后 再次授权

    //单机去搜索 toSearch:function(){ this.getLocation(res => { console.log('成功') wx.navigateTo({ url: `.. ...

  6. HDOJ 2828 Lamp DLX反复覆盖

    DLX反复覆盖模版题: 每一个开关两个状态.但仅仅能选一个,建2m×n的矩阵跑DLX模版.. .. Lamp Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  7. [ACM] hdu 4248 A Famous Stone Collector (DP+组合)

    A Famous Stone Collector Problem Description Mr. B loves to play with colorful stones. There are n c ...

  8. django 笔记9 分页知识整理

    感谢老男孩 自定义分页 XSS:攻击 默认字符串返回 {{page_str|safe}} 前端 from django.utils.safestring import mark_safe page_s ...

  9. Why functions - Not only for python

    It may not be clear why it is worth the trouble to divide a program into functions. There are a lot ...

  10. 36.创建模板mylist

    node.h #pragma once //创建模板 template <class T> class Node { public: T t;//数据 Node *pNext;//指针域 ...