c语言-指针统计字符串长度,字符串连接

来源:互联网 发布:阿里通信卡的网络2g 编辑:程序博客网 时间:2024/05/01 07:14
#include "stdio.h"int main(){              char s[100]="hello";        char b[]="world";        int len=mystrlen(s);        printf("len=%d\n",len);        mystradd(s,b);        printf("s=%s\n",s);}int mystrlen(char s[]) //求字符串长度方法{        int len=0;        char *p=s;        while(*p)        {                  len++;                p++;        }           return len;}void mystradd(char s[],char b[]) //字符串连接方法;{        int len=mystrlen(s);        char *ps=&s[len];        char *pb=b;        while(*pb)        {                *ps=*pb;                ps++;                pb++;        }}
1 0
原创粉丝点击