|
|
View previous topic :: View next topic |
Author |
Message |
jackhammer
Joined: 05 Sep 2011 Posts: 8
|
comparison of char variable and if How to use |
Posted: Sun Sep 25, 2011 3:59 am |
|
|
i have array char variable
Code: | char Code[]{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; |
suppose
i want stop program at Code[4]
How to use if for char variable because do not int variable
if(Code[]=4)
{stop program}
if(Code=4)
{stop program}
ู^
^
^
ERROR all What have any way
if(??????????)
{stop program}
I did not expert C language and english language |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Sun Sep 25, 2011 5:20 am |
|
|
CCS kindly provides a folder FULL of great examples of programming their C compiler as well as a huge onscreen help file(press F11 to open).
It sounds like you need a 'C programming for dummies' book. I have one though not a huge help in programming on a PIC. There are several books on the subject though I've never bought any as just push F11 when needed.
What you need to know is there and you can always 'google' for more
help. I do understand the language problem as I have used some 27 different computer languages in the 30+ years of doing this. |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun Sep 25, 2011 8:05 am |
|
|
You don't need to be an "expert" but you do need to know the
fundamentals of C programming. Unfortunately, this forum is not here to
teach C programming, you will need to learn that elsewhere.
To get you started, below are a few pointers.
First , to use an array you must learn how to address the elements. In
your example what element of the Code array are you trying to address?
Code: | if(Code[]=4)
{stop program}
|
Second you need to learn the difference between assignment and
comparison. Do some research on the difference between one (=) and two
(==) equals signs.
How array comparisons should look:
if (Code[0]==0x3f) (also, remember array numbering starts at zero not 1)
Third, keep in mind when comparing a value, it must precisely MATCH
what is desired:
(examples: 0x66 is NOT the same as 66, '7' is NOT the same as 7).
Fourth, you need to learn how to structure an array definition:
Code[]{0x11,0x12,0x13 etc } is NOT correct. (Read the C and CCS manuals) _________________ Google and Forum Search are some of your best tools!!!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|