I am just learning C programming and and working through 'The C Programming Language' by Dennis Ritchie.
I am just starting to explore arrays and am working on a sample piece of code in the book which counts digits, whitespace and other characters input.
I have recieved the error 'lvalue required as left operand of assignment on line 16 of the code which reads as follows:
else if (c == ' ' || c == '\n' || c = '\t')
The complete code for the program is:
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int c, i, nwhite, nother;
int ndigit[10];
nwhite = nother = 0;
for (i = 0; i < 10; ++i)
ndigit[i] = 0;
while ((c = getchar())!= EOF)
if (c >= '0' && c <= '9')
++ndigit[c-'0'];
else if (c == ' ' || c == '\n' || c = '\t')
++nwhite;
else
++nother;
printf("digits =");
for (i = 0; i < 10; ++i)
printf(" %d", ndigit[i]);
printf(", white space = %d, other = %d\n", nwhite, nother);
}
Can someone explain why this error is occuring, I can see nothing wrong with it nor any of the rest of the code in the program.