Xcode 上的 C:访问错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16009667/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:13:19  来源:igfitidea点击:

C on Xcode: bad access

cxcodeexc-bad-access

提问by Haoyao Chen

I am trying to finish an assignment for my Cprogramming class on Xcode. It's simple. It reads a text file, which contains a list of student IDs and their test scores. And then it calculates the overall score based on these data, and writes them to another text file. However, I keep getting this Bad Accesserror message that says:

我正在尝试完成我的C编程课的作业Xcode。这很简单。它读取一个文本文件,其中包含学生 ID 及其考试成绩的列表。然后它根据这些数据计算总分,并将它们写入另一个文本文件。但是,我不断收到此Bad Access错误消息,内容为:

Thread 1: EXC_BAD_ACCESS(code=1, address=0x7fff00000de4)

I don't know what it means. What should I do?

我不知道这是什么意思。我该怎么办?

回答by Alex

The EXC_BAD_ACCESSmeans that you tried to attempt the incorrect address in memory.

EXC_BAD_ACCESS意味着您试图在内存中尝试错误的地址。

You should start with the following:

您应该从以下几点开始:

  1. Check that all pointers are initialized before using
  2. If you have an array, so possibly you are trying to access the element that is out of bounds
  1. 使用前检查所有指针是否已初始化
  2. 如果您有一个数组,那么您可能正在尝试访问越界的元素

And of course, use the debugger.

当然,使用调试器。