Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

c - "lvalue required as left operand of assignment " error

The following code produces a "lvalue required as left operand of assignment"

if( c >= 'A' && c <= 'Z'  || c = " " || c = ",") {

I assume I'm writing this wrong, what is wrong? and how would I write it correctly?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should use single quotes for chars and do double equals for equality (otherwise it changes the value of c)

if( c >= 'A' && c <= 'Z'  || c == ' ' || c == ',') {

Furthermore, you might consider something like this to make your boolean logic more clear:

if( (c >= 'A' && c <= 'Z')  || c == ' ' || c == ',') {

Although your boolean logic structure works equivalently (&& takes precedence over ||), things like this might trip you up in the future.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...