hello, i am using keil uvision 4.0 for my 8051 projects.i am getting an error whenever i use the pre defined word 'else' in my code. ex:
if(an1==1)
{
LED1=1;
LED2=1;
else //at this point//
LED1=0;
LED2=0; }
it shows an error C141. Can you please help me out..
sure, but your problem show such a lack of understanding the basic C concepts, not to mention that you are unable to follow instructions (re posting code), that helping you would make you come back with an equally basic problem in a few minutes
get a C book, study it
Erik
Learn how to use/apply compound statements properly.
if(an1==1) { LED1=1; LED2=1; } // Brace here else { // Brace here LED1=0; LED2=0; }
I had the exact same problem when I started!!!!
That was the help I needed. Nice not to get the 'teach a man a fish' crud.
I see no one did teach you to fish - it isn't "teach a man a fish".
But more importantly: do you think it is a bad idea to tell someone that they should spend some time with a book about the C language? In what way is that bad? You prefer that people learn without books - asking about every single aspect of the language on a forum? But how can someone ask about a concept they don't even know exists?
"Nice not to get the 'teach a man a fish' crud."
Yeah, learning the language -- that's so lame.
We could fix your syntax errors faster if you publish your code to a public repository for us to directly edit.
Man, do you suffer from tunnel vision?
What I'm saying is that I once got caught on the very same problem. I had some books, but nothing seemed to make sense. Then someone told me the same like explained here. It was the nudge I needed so my learning could commence and continue and progress.
If some dumb-ass fool had just said 'read the manual', I might have just given up. But I was lucky. Someone gave me that nudge and I am eternally grateful to them. Without that, I would possibly have ended up in a dead end, pretentious job. I could even have shamed my family and become ... a ... consultant (weep).
A least I'm sagacious enough to recognize when Please read the manual isn't the appropriate answer.
And for what it's worth, I admire your keen mental discernment and good judgment that you show in such matters.
"Man, do you suffer from tunnel vision?"
No, but I constantly suffer from people not realizing the reason for tagging posted source code properly since indentation was an important step in the development of modern programming languages.
With source code properly indented, and with a look at "block statements" in a C book, it would be obvious that this poor "else" didn't have any family to reunite with.
The interesting thing is also that we constantly gets posts with "i am getting an error" instead of posts that specifically writes out the error message the compiler emits. For some very strange reason, the error messages quite often adds some clues what might be wrong.
It is way easier to "nudge" people with specific information when they show they have spent some time looking into issues and trying to eliminate possible error sources.
Something as simple as googling for "how to use else in C" would have given lots and lots of hints what could have been wrong with the posted source code. But for people who don't like to google individual issues (there are billions of possible ways things can go wrong) it is normally better to get a good C book and work through it since it will cover quite a lot of potential hurdles.
In the end, people do need to learn how to fish, unless they have the money to always buy the fish. Just that schools doesn't allow the students to buy the solutions from consultants.
What a load of bluster.
I'm just glad the person I asked recognised what I needed when I needed it. Sometimes there is no excuse, a simple question can be best dealt with by giving a simple, straightforward and direct answer. Obviously, you are too 'good' to believe that.
The problem is not about the braces. I tried that out too!!..
So what _does_ your fixed code look like that still gives you that error?
Note: post properly intended and with the correct tags, as described in the posting tips.