product->scheme->edit scheme->Run->options->把 using custom working directory前面的勾选上。然后填写相对路径及可以。。下图
![](https://img.haomeiwen.com/i1694726/8d7b864fb6b41f0d.png)
// 然后这样写就好了
char filePath[] = "./CFileDemo/testJson.json";
FILE *file = fopen(filePath, "r+");
if (file == NULL) {
printf("testJson 打开失败, errno = %d; \n",errno);
} else {
}
// 起初我以为iOS里面bundle也可以 这样用,但事实是bundle里面的数据只有读取的权限,要沙盒里面的文件才可以有读取和写入权限,
C的书
推荐: http://book.douban.com/subject/1230004/ ,
还可以用: http://c.learncodethehardway.org/book/ 这个当参考和练习
网友评论