#include <stdio.h>
#include<string.h>
/*基本水平*/
void mycopy1(char *des,char * sou)
{
unsigned int i;
for ( i = ; i < strlen(sou); i++)
{
des[i] = sou[i];
}
des[i] = '\0';//加上结束符
} /*初级水平*/
void mycopy2(char *des, char * sou)
{
while (*sou != '\0')
{
*des++ = *sou++;
}
*des = '\0';//同样加上结束符
} /*中级水平*/
void mycopy3(char *des, char * sou)
{
while( (*des++ =*sou++)!='\0')
{ }
//*des = '\0';//不再需要这句话
}
/*高级水平*/
void mycopy4(char *des, char * sou)
{
while (*des++ = *sou++)
{ }
//*des = '\0';//不再需要这句话
}
/*
注意,这里要求sou指针指向的是以'\0'结尾的字符串,如果都是字符数组,则不行,当然你也可以在
字符数组尾部加上'\0',让它成为一个判断标志
这个主要是锻炼思维,第四中情况,将在《c和指针》上看到应用,后续举例
*/
int main(void)
{
char str[] = "abcdef";
char str1[]; mycopy1(str1,str);
printf("str1=%s\n", str1); mycopy2(str1, str);
printf("str1=%s\n", str1); mycopy3(str1, str);
printf("str1=%s\n", str1); mycopy4(str1, str);
printf("str1=%s\n", str1);
return ;
}

字符串copy推导演变的更多相关文章

  1. 字符串copy

    #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #include<string. ...

  2. C++ 拆分字符串-copy()

    c++拆分字符串方法: #include <iostream>#include <string>#include <sstream>#include <alg ...

  3. C语言字符串操作总结大全

    1)字符串操作 strcpy(p, p1)  复制字符串  函数原型strncpy(p, p1, n)   复制指定长度字符串  函数原型strcat(p, p1)   附加字符串  函数原型strn ...

  4. C语言字符串操作总结大全(超详细)

    本篇文章是对C语言字符串操作进行了详细的总结分析,需要的朋友参考下 1)字符串操作  strcpy(p, p1) 复制字符串  strncpy(p, p1, n) 复制指定长度字符串  strcat( ...

  5. c语言的字符串操作(比较详细)

    1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat(p, p1) 附加字符串 strncat(p, p1, n) 附加指定长度 ...

  6. Windows内核下操作字符串!

    * Windows内核下操作字符串! */ #include <ntddk.h> #include <ntstrsafe.h> #define BUFFER_SIZE 1024 ...

  7. C++ Strings(字符串)

    Constructors 构造函数,用于字符串初始化 Operators 操作符,用于字符串比较和赋值 append() 在字符串的末尾添加文本 assign() 为字符串赋新值 at() 按给定索引 ...

  8. C语言字符串操作函数集

    1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat(p, p1) 附加字符串 strncat(p, p1, n) 附加指定长度 ...

  9. Go 字符串连接+=与strings.Join性能对比

    Go字符串连接 对于字符串的连接大致有两种方式: 1.通过+号连接 func StrPlus1(a []string) string { var s, sep string for i := 0; i ...

随机推荐

  1. html 链接外部css js文件

    <link rel="stylesheet" type="text/css" href/style.css" />    <scri ...

  2. topas解析(AIX)

    topas解析   topas 的显示信息和解析 (1) topas monitor for host:localhost  topas监控的主机名称localhost tue Aug 14 14:1 ...

  3. Word基础总结

    Word文本的操作 一.文 ◎Backspace(退格键) 删除光标以左的内容    ◎Delete (删除键)    删除光标以右的内容     #实话之前一直没在意,一直用backspace删除 ...

  4. 【mysql】Innodb三大特性之adaptive hash index

    1.Adaptive Hash Indexes 定义 If a table fits almost entirely in main memory, the fastest way to perfor ...

  5. 单节点k8s的一个小例子 webapp+mysql

    安装kubernetes 准备一台centos7 1) 关闭firewalld 和 selinux systemctl stop firewalld systemctl disable firewal ...

  6. cxf之生成客户端代码

    wsdl2java –d . http://192.168.1.100:1234/weather?wsdl

  7. Web前端开发笔试&面试_02(others)

    AL>> 1.CSS 3 如何实现旋转图片? 答:transform : rotate 2.写CSS 的工具? 答:LESS.SASS 3.JavaScript 倒计时? 答:setTim ...

  8. 【LeetCode】120. Triangle (3 solutions)

    Triangle Given a triangle, find the minimum path sum from top to bottom. Each step you may move to a ...

  9. RHCE7 管理II-2 通过grep使用正则表达式

    grep -i:忽略大小写 -n:表示行数 找出含有root的行 # grep root /etc/passwd root:x:::root:/root:/bin/bash ::operator:/r ...

  10. Android LinearLayout的android:layout_weight属性

    本文主要介绍Android LinearLayout的android:layout_weight属性意义 android:layout_weight为大小权重,相当于在页面上显示的百分比,它的计算是根 ...