尝试在 C 中执行 strcat 函数时的 EXC_BAD_ACCESS [英] EXC_BAD_ACCESS When Trying to Perform a strcat Function in C

查看:40
本文介绍了尝试在 C 中执行 strcat 函数时的 EXC_BAD_ACCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 C 为 uni 编写的程序,当我的代码到达这一行时:

I have a program I am writing for uni in C, and when my code reaches this line:

strcat("md5 ", "blah");

我收到了 EXC_BAD_ACCESS 错误,我的应用程序崩溃了.据我所知,它没有任何问题,所以我认为一双新的眼睛可能会解决我的问题.有什么想法吗?

I am getting a EXC_BAD_ACCESS error, and my app crashes. As far as I can tell, there isn't anything wrong with it, so I thought a fresh pair of eyes might solve my problem. Any ideas?

推荐答案

您正在尝试修改常量字符串.strcat 的第一个参数也是目标字符串,在您的情况下它是一个常量字符串.你应该使用类似的东西:

You're trying to modify a constant string. The first argument of strcat is also the destination string and in your case it is a constant string. You should use something like:

char s[100];
strcpy(s, "md5 ");
strcat(s, "blah");

这篇关于尝试在 C 中执行 strcat 函数时的 EXC_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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