我正在使用 Visual Studio 2013 来尝试学习 C 语言。
我正在使用著名的K&R book将书中的以下代码片段复制并粘贴到 Visual Studio 2013 后,我收到错误:
1 error C2106: '=' : left operand must be l-value
2 IntelliSense: expression must be a modifiable lvalue
#include <stdio.h>
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
/* count lines, words, and characters in input */
main()
{
int c, nl, nw, nc, state;
state = OUT;
nl = nw = nc = 0;
while ((c = getchar()) != EOF) {
++nc;
if (c == '\n')
++nl;
if (c == ' ' || c == '\n' || c = '\t')
state = OUT;
else if (state == OUT)
state = IN;
++nw;
}
printf("%d %d %d\n", nl, nw, nc);
}
看来错误来自于以下语句:
if (c == ' ' || c == '\n' || c = '\t')
但我真的不知道出了什么问题,更不用说代码是直接来自书中的事实了。
任何帮助将不胜感激!
谢谢!
最佳答案
if (c == ' ' || c == '\n' || c = '\t')
// ^ Oops.
建议你休息一下。即使不知道分配会尝试写入 ||
的结果,因为它的优先级较低,但差异还是很大。
关于C - 无法找出此错误 : "C2106: ' =' : left operand must be l-value",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28256556/