zoukankan      html  css  js  c++  java
  • 指针方法完成字符串的复制

    //指针方法完成字符串的复制
    #include<stdio.h>
    void main()
    {
        void copy_string(char *from,char *to);
        char *fro,*t;
        char a[]="I am a teacher.";
        char b[]="You are a student.";
        printf("a=%s\nb=%s\n",a,b);
        fro=a;t=b;
        printf("\ncopy string a to string b:\n");
    
        copy_string(fro,t);//此处不用带指针符号*
        printf("string a=%s\nstring b=%s\n",a,b);
    }
    void copy_string(char *from,char *to)
    {
       // int i=0;
        while(*from!='\0')
        {
            *to=*from;
            from++;to++;
        }
        *to='\0';//字符串的最后一个字符为\0
    }

         指针做形参和实参,完成字符串的复制。

         刚开始运行两三遍,到后面突然出现这个问题,ld.exe||cannot open output file H:\学习心得\我的C语言进化史\copy_string.exe,百度之后,

    “可能这个012.exe已经在运行状态,需要关闭才能编译”。明白是程序仍在后台运行,不能再次编译运行,感觉是程序哪里没写好,才发现没有定义main函数的类型,
    所以可能电脑不知道返回值是什么,一直在运行。
    解决方法:打开windows控制台cmd,杀死进程,taskkill -IM 012.exe /F, 把占用该文件的进程强制杀掉,就可以编译。
    那指针这块现在就训练结束啦。
  • 相关阅读:
    State Management
    排序效率小PK
    ES,ZK,Mysql相关参数优化
    ES翻译之Function Score Query
    打算坚持学习技术的习惯
    面试——并发基础知识1
    码云的GIT操作
    CountDownLatch模拟高并发测试代码
    Bloom Filter的应用
    面试题1—选取同一个字符第一不重复的字符
  • 原文地址:https://www.cnblogs.com/sunmarvell/p/5948242.html
Copyright © 2011-2022 走看看