EXC_BAD_ACCESS 将字符写入txt文件
#include <stdio.h>
int main (int argc, const char * argv[])
{
FILE *fp;
fp=fopen("/Users/--------/Desktop/C.txt", "w");
putc("C", "/Users/-------/Desktop/C.txt");
fclose(fp);
}
这是我将字母“C”写入文本文件 C.txt 的简单代码。每次写入时都会收到错误代码 EXC_BAD_ACCESS。发生什么事了?
#include <stdio.h>
int main (int argc, const char * argv[])
{
FILE *fp;
fp=fopen("/Users/--------/Desktop/C.txt", "w");
putc("C", "/Users/-------/Desktop/C.txt");
fclose(fp);
}
Here is my simple code for writing the letter "C" into the textfile C.txt. I get the error code EXC_BAD_ACCESS every time I write it. Whats happeneing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
putc
不应该这样使用。尝试:putc
看起来像这样:您传递的是
char *
而不是FILE *
。That's not how
putc
should be used. Try:putc
looks like this:You are passing a
char *
instead of aFILE *
.请尝试以下操作:
putc 期望其第二个参数是 FILE*,而不是文件的路径。
第一个参数也应该是 char,而不是示例中的 char* 。
Try the following:
putc expects its second parameter to be
FILE*
, not a path to the file.First parameter should also be char, not char* as in your example.
您应该写入该文件:
此外,您应该检查
fopen
没有返回NULL
You should write to the file:
Also, you should check that
fopen
didn't returnNULL