sunmarvell
//指针方法完成字符串的复制
#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, 把占用该文件的进程强制杀掉,就可以编译。
那指针这块现在就训练结束啦。

分类:

技术点:

相关文章:

  • 2021-07-12
  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-09-25
猜你喜欢
  • 2022-12-23
  • 2021-08-14
  • 2021-08-08
  • 2022-12-23
  • 2021-08-07
  • 2021-11-06
  • 2021-05-19
相关资源
相似解决方案