gpt4 book ai didi

c - 在 linux 下使用 C 读取 txt。我应该把txt文件放在哪里?

转载 作者:太空宇宙 更新时间:2023-11-04 08:27:51 25 4
gpt4 key购买 nike

我正在尝试在 Linux 下使用 C 读取 txt 文件。 FILE*fp=fopen("test.txt","r");我有上面的代码,但它告诉我“段错误(核心转储)”。这是因为我的 txt 文件不在正确的目录下吗?

int main(int argc, char*args[])
{
//printf("%d\n", argc);
int i;
for(i=0;i<argc;i++)
{
printf("%s ", args[i]);
}
int numProcesses=10;
int memorySize=atoi(args[1]);
int pageSize=atoi(args[2]);
int alloAlg=atoi(args[3]);
int evicAlg=atoi(args[4]);
int globLoc=atoi(args[5]);
int peroid=atoi(args[6]);

FILE*fp;
fp=fopen("Desktop/plist.txt","r");
char buff[1000];
//fgets(buff,100,fp);
//printf("%s",buff);
}

最佳答案

当您打开没有路径的文件时,假定该文件位于当前目录中。至于你的段错误——你应该在尝试读取/写入之前针对 NULL 测试 FILE 指针。

关于c - 在 linux 下使用 C 读取 txt。我应该把txt文件放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29618156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com