参考代码
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
// 获取应用程序的“Documents”目录
char *documentsPath = getenv("HOME");
// 指定要保存的文件名和路径
char filepath[1024] = {0};
sprintf(filepath, "%s/Documents/file.txt");
// 要保存的内容
char *content = "Hello, world!";
// 打开文件,以写入方式打开
FILE *file = fopen(filepath, "w");
if (file != NULL) {
// 将内容写入文件
fprintf(file, "%s", content);
// 关闭文件
fclose(file);
}
return 0;
}
导出文件
旧版的mac使用itunes导出,新版的itunes没有了,使用xcode导出
- 在xcode-window-Devices and Simulators 找到调试的应用程序
- 点击 download container
- 会将应用数据整个下载到本地,一般是finder的目录
- 右键-显示包内容,就可以看到保存的文件了,拖到finder当中即可