它总是提示"code will never be executed"
It always prompts "code will never be executed"
这是我的C++代码:
#include <stdio.h>
int main ()
{
int n, ip1, ip2, ip3, ip4, port;
unsigned ip;
char str [80];
printf ("Enter IPv4 address: ");
scanf ("%79s",str);
n = sscanf(str, "%3d.%3d.%3d.%3d:%5d", &ip1, &ip2, &ip3, &ip4, &port);
printf ("Content length is %drn", n);
if (n != 4 || n != 5) {
ip = 0;
port = 161;
}
else if (n==4) {
port = 161;
}
ip =(ip1 << 24) + (ip2 << 16) + (ip3 << 8) + ip4;
printf ("ip addr is %d , port is %d rn", ip, port);
}
但xcode总是提示我:
else if (n==4)
永远不会被处决,而且确实发生了。条件应该如何?
请注意,(n != 4 || n != 5) = true
您可能想要if (n != 4 && n != 5)
,因为如果使用||
,那么n
要么不是4,要么不是5。
相关文章:
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 使用模板进行堆栈实现; "name followed by :: must be a class or namespace"
- 这对"With a stackless coroutine, only the top-level routine may be suspended."意味着什么
- 为什么我会" void value not ignored as it ought to be"?
- 如何解决"no Qt platform plugin could be initialized"问题?
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- 如何修复输出日志中的"EnableInput can only be specified on a Pawn for its Controller"错误
- _BitScanForward64 can not be found
- C++复制函数重载导致"must be a nonstatic member function"错误
- 通过分隔符分隔包含 UTF-16 BE 文本的uint8_t数组
- C++ 错误:"array must be initialized with a brace-enclosed initializer"
- "expression must be a modifiable lvalue"是什么意思?
- 如何摆脱导入的 make 项目中的 Eclipse 索引器"Type std::... could not be resolved"错误
- Qt5 部署"procedure entry point could not be located"
- 为什么"types may not be defined in parameter types"
- 如何修复警告"the compiler can assume that the address of 'object' will never be NULL"
- Clang - 删除某些文件的"conversion function converting <A> to base class <B> will never be used"
- 它总是提示"code will never be executed"
- "reference can never be made to refer to another object"是什么意思?
- 在"warning: will never be executed"中使用'g++'结果