关于strcpy()的疑问 [英] Doubt regarding strcpy()

查看:101
本文介绍了关于strcpy()的疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我在代码中使用strcpy()将字符串复制到另一个字符串。

i我正在使用静态字符数组。


第一次正确执行但是第二次

控制到达然后发生了SEGMENTATION FAULT。


请告诉我如果我们使用

strcpy()可能会出现这种情况。


谢谢

解决方案

edu.mvk写道:





我在我的代码中使用strcpy()将字符串复制到另一个字符串。

i我正在使用静态字符数组。


第一次被执行正确,但第二次

控制到达然后发生了分段故障。


请告诉我如果我们使用这个问题可能会发生什么

strcpy()。



这是不可能的o列举所有案例。你将无效的

参数传递给strcpy()。


最有可能是以下之一:

1.源char *不指向null终止

序列的char'。


2.目标字符*没有指向开头

的字符数组足以容纳复制的字符串。


edu.mvk写道:


我在我的代码中使用strcpy()将字符串复制到另一个字符串。

i我正在使用静态字符数组。



你应该尝试使用C ++提供的工具而不是旧的和

危险的C设施。

< br>

edu.mvk写道:





我在我的代码中使用strcpy()将字符串复制到另一个字符串。

i我正在使用静态字符数组。


第一次正确执行但是第二次

控制到达然后发生SEGMENTATION FAULT。


请告诉我如果我们使用

strcpy会出现这种情况的原因是什么? )。



编号。告诉我们您的代码,我们将具体告诉您去哪里

错误。查看新闻组常见问题列表:


< http://www.parashift.com/c++-faq-lite/how-to-post.htm>

否则,在C上获取一本教科书并阅读strcpy。当你知道

它是如何工作的时候,你可以很容易地找出什么是行不通的。


Brian


Hi

I am using strcpy() in my code for copying a string to another string.
i am using static char arrays.

for the first time it is exected correctly but the second time the
control reaches then the SEGMENTATION FAULT is occuring.

Please tell me what are all the cases this problem may occur if we use
strcpy().

Thanks

解决方案

edu.mvk wrote:

Hi

I am using strcpy() in my code for copying a string to another string.
i am using static char arrays.

for the first time it is exected correctly but the second time the
control reaches then the SEGMENTATION FAULT is occuring.

Please tell me what are all the cases this problem may occur if we use
strcpy().

It''s impossible to enumerate all the cases. You''re passing invalid
arguments to strcpy().

Most likely it''s one of the following:

1. The source char* doesn''t point to a null terminated
sequence of char''s.

2. The destination char* doesn''t point to the beginning
of an array of chars big enough to hold the copied string.


edu.mvk wrote :

I am using strcpy() in my code for copying a string to another string.
i am using static char arrays.

You should try to use the tools C++ provides instead of old and
dangerous C facilities.


edu.mvk wrote:

Hi

I am using strcpy() in my code for copying a string to another string.
i am using static char arrays.

for the first time it is exected correctly but the second time the
control reaches then the SEGMENTATION FAULT is occuring.

Please tell me what are all the cases this problem may occur if we use
strcpy().

No. Show us your code and we will tell you specifically where you went
wrong. See the newsgroup FAQ list:

<http://www.parashift.com/c++-faq-lite/how-to-post.htm>
Otherwise, get a textbook on C and read up on strcpy. When you know how
it works, then you can pretty easily figure out what doesn''t work.

Brian


这篇关于关于strcpy()的疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆