Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me with CCS string in PIC C Compiler

Status
Not open for further replies.

Sobakava

Full Member level 6
Joined
Mar 27, 2002
Messages
350
Helped
8
Reputation
16
Reaction score
8
Trophy points
1,298
Activity points
3,342
CCS String Compare

How can I make something like this in
CCS PIC C Compiler?

char str1[10];


switch(str1) {
case "abcd" : dosomething...;
case "efgh" : dosomethingelse;
}

or
if (str1=="abcd") { dosomething }

!!
strcmp(str1,str2) does not work with constants
like "abcd".
!!

how can i make it with a memory effective method?

regards.
 

Does the switch statement work?
I only used it with integers (but hey, they're just a number of bytes like a char array ;-) )

Does the compare work? Did you or one of the libraries overload the == operator so you can compare char arrays?

most of the time i just use memcmp(string1, string2, nrofchars);
it returns 0 it strings are equal and an other number when they aren't
(it's also usefull to sort alfabetically i guess ;-) )
just look for information on the net. It's a standard library function.

what do you mean with memory effective?
do you mean the fasted method or the one that compiles to the smallest code. (perhaps you should try a few methods since it can be compiler dependant)
When you realy have to have small and fast code, write it in assembly and link against it.
 

Re: CCS String Compare

Sobakava said:
How can I make something like this in
CCS PIC C Compiler?

char str1[10];


switch(str1) {
case "abcd" : dosomething...;
case "efgh" : dosomethingelse;
}

or
if (str1=="abcd") { dosomething }

...
regards.

note that when you're doing like this you compare only pointers (not data in string). I've never used CCS PIC C Compiler but programmed much in C including microcontrollers, and I think there shuld be some library like string.h or similar with comparing function. If not - write such function by your own!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top