鱼C论坛

 找回密码
 立即注册
查看: 3241|回复: 0

请教 函数调用字符串复制 提示 堆叠变量B损坏的问题

[复制链接]
发表于 2013-4-17 23:52:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
首先 按照 甲鱼哥的思路  自行编写成功

但是后来发现  修改a字符串  在之后增添字符  长度超过 b字符串  则会提示 stack around the variable 'b' was corrupted。

用甲鱼哥可见里面的代码 增添同样如此。

是留下的坑吗?

求教是怎么回事  ?

贴上代码如下

#include <stdio.h>

void  main()
{
      void  copy_string(char from[], char to[]);

      char a[] = "I am a teacherrrrrrrrr.";
      char b[] = "You are a student.";

      printf("string a = %s\nstring b = %s\n", a, b);
      printf("copy string a to string b:\n ");

      copy_string(a, b);

      printf("\nstring a = %s\nstring b = %s\n", a, b);
}

void  copy_string(char from[], char to[])
{
      int i = 0;

      while( from[i] != '\0' )
      {
            to[i] = from[i];
            i++;
      }
      to[i] = '\0';
}



小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-8-2 19:15

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表