我有一个程序通过从文件中读取命令来接受订单。在这个文件中有些命令是“float string”,比如“1.0”,“2.0”,但是它们是无效的,程序需要的是整数,比如“1”,“2”。那么,我怎样才能让程序理解像“1.0”这样的命令是无效的呢?有什么巧妙的方法可以做到这一点吗?
char buf[CMDSIZE];
if(fgets(buf, CMDSIZE, stdin)) //buf likes this: "1.0 \n"
{
*prio = 1; *command = -1; *ratio =1.0;
// I need to make sure that command is not "1.0" or something like this
sscanf(buf, "%d", command);
switch(*command){....blahblah......}
}
谢谢你。