我试图让一个程序从 C 中的命令行运行,它需要输入文件目录并输入变量。我正在尝试使用 stricmp 函数来读取键入到命令行中的代码,但我不知道如何让它读取文件(我读取了你应该输入“r”的文件路径)并执行计算。我在想 scanf 也许我还需要能够输入变量。如果有人可以查看我的代码并给我一些指示,我将不胜感激。谢谢!
int main(int argc, char *argv[])
{
int i = 0;
for(i < argc; i++;)
{
if(0 == stricmp("Interrogator MLV_PLV_179 r %s %s", argv[i]))
{
InterrogatorProtocol1553Flag = TRUE;
// Set DMV-179
Interrogator_OFP_Select = INT_OFP_DMV_179;
// Set MLV/PLV (Dim S-Record File)
DirectFlashProgFlag = FALSE;
// Set Fill Type to 1
Interrogator_PIR_OFP_FOP = 3;
Interrogator_PIR_ProgramID = (Interrogator_PIR_T_I << 11) |
(Interrogator_PIR_OFP_FOP << 5) |
Interrogator_PIR_RT_Address;
}
else if(0 == stricmp("Interrogator DirectFlash r r %s %s", argv[i]))
{
InterrogatorProtocol1553Flag = TRUE;
Interrogator_OFP_Select = INT_OFP_DMV_179;
DirectFlashProgFlag = TRUE;
CreateInterrogatorFlashImage;
}
else if(0 == stricmp("Interrogator MLV_PLV_183 r %s %s", argv[i]))
{
InterrogatorProtocol1553Flag = TRUE;
// Set DMV-183
Interrogator_OFP_Select = INT_OFP_DMV_183;
// Set MLV/PLV (Dim S-Record File)
DirectFlashProgFlag = FALSE;
// Set Fill Type to 6
Interrogator_PIR_OFP_FOP = 6;
Interrogator_PIR_ProgramID = (Interrogator_PIR_T_I << 11) |
(Interrogator_PIR_OFP_FOP << 5) |
Interrogator_PIR_RT_Address;
}
else if(0 == stricmp("Interrogator SRecord r r %s %s", argv[i]))
{
InterrogatorProtocol1553Flag = TRUE;
Interrogator_OFP_Select = INT_OFP_DMV_183;
DirectFlashProgFlag = TRUE;
CreateIntermediateSRecordFile;
}
else
{
fprintf(stderr, "Unknown parameter: %s", argv[i]);
}
}
return 0;
}