有没有干净的方式来打开这样的文件,而无需系统调用:的fopen一个文件,并跳过字符
ID*_LogConfig.csv
我尝试以下,但它并没有奏效。
/*Read setup file*/
getcwd(cwd, sizeof(cwd));
snprintf(source, sizeof(source),"%s/ID%*d_LogConfig.csv",cwd);
if(NULL == (input = fopen(source,"r")))
{
snprintf(errbuffer,sizeof(errbuffer), "Could not open file %s - check existence/rights\n", source);
exitHandler(1, errbuffer);
}
它输出:
/mnt/dataflash/canfilter.d/ID*_LogConfig.csv not found
但是与例如cat /mnt/dataflash/canfilter.d/ID*_LogConfig.csv它显示文件内容。
我的折衷的解决方案将是一个系统调用ll ID*_LogConfig.csv
并使用输出文件名。
'll'不是系统调用。这是一个由shell调用的程序。这也是预制棒替代品的外壳。 – StoryTeller
不是'%* d'期望宽度和'int'参数吗?尝试'snprintf(source,sizeof(source),“%s /%s”,cwd,“ID * _LogConfig.csv”);' – chux
什么是'cwd'?什么是“源”?什么是'errbuffer'?请将这些定义添加到您的问题中。 – wildplasser