如何解决将文件作为命令行参数传递不会在 CLion 中注册为路径
我试图将文件作为参数传递给我的代码,但我无法获得文件名以匹配 CLion 上的文件路径。基本上,当我尝试打开文件进行读取时,它最终为空(可能是路径错误)。我尝试将绝对路径放入 fopen 函数中,效果很好。文本文件与 .c 文件位于同一文件夹中。对此有什么建议吗?
char* inputFile = argv[1];
char* outputFile = argv[2];
int start = atoi(argv[3]);
int end = atoi(argv[4]);
char *target = argv[5];
char *replacement = argv[6];
if (start > end || start < 1 || end < 1)
{
return 1;
}
char line[102];
FILE *input = fopen(inputFile,"r"); # input is NULL
# if you change the variable inputFile to the absolute path of the file instead,# the program runs just fine
while(fgets(line,102,input))
{
printf("x");
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。