如果声明没有意义 [英] If Statement Doesn't Make Sense

查看:78
本文介绍了如果声明没有意义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个if语句的最后一个语句对我来说没有意义还是对?

The last statement of this if statement isn''t making sense to me or does it?

   // Check arguments
   if ( _argc > 1 )
   {
      if ( !_stricmp(_argv[1], "icmp") )
{ //<-- Need to add brackets for more than one statement
   bShowTCP = FALSE;
   bShowUDP = FALSE;
}
else if ( !_stricmp(_argv[1], "tcp") )
{
   bShowUDP = FALSE;
   bShowICMP = FALSE;
}
else if ( !_stricmp(_argv[1], "udp") )
{
   bShowTCP = FALSE;
   bShowICMP = FALSE;
}
else
{
   bShowUDP = TRUE; //<-- Needs to be within else statement brackets
   printf( "\nUsage lsniff [ICMP|TCP|UDP]\n" );
   exit(0); //<-- FYI... this ends execution of the program

}
   }

推荐答案

如果您输入的值不是icmp,tcp或udp之一,这确实有意义.
如果没有在参数中输入以上三种类型,则程序开发人员希望程序退出.
It does make sense if your input value is not one of icmp,tcp or udp.
The developer of the program wants the program to exit if none of the above three types have been entered in the argument.


我没有发现任何错误.如果您想知道为什么它是!_stricmp,那是因为如果字符串相同,则C字符串比较将返回0,并且!0是一个真值.

我不确定为什么要在其他地方设置bShowUDP.
I see nothing wrong. If you''re wondering why it''s !_stricmp it''s because C string comparisons return 0 if the strings are the same, and !0 is a true value.

I''m not sure why they bother to set bShowUDP in the else though.


我没有发现代码有什么问题.我相信您希望像在else if子句中一样,在else子句旁边有一个表达式. else子句不带任何表达式,并且如果语句中没有其他if子句被执行,则该子句将被执行.
I don''t see anything wrong with the code. I believe you are expecting an expression next to the else clause as in the preceding else if clauses. The else clause does not take any expression and is executed if no other if clause in the statement is executed.


这篇关于如果声明没有意义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆