View previous topic :: View next topic |
Author |
Message |
Guest
|
#define a string |
Posted: Sat Aug 27, 2005 3:40 pm |
|
|
Is this permitted? #define string (char*)"hi"
If not, any suggestions? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Aug 27, 2005 4:43 pm |
|
|
pointers to constants are not allowed. |
|
|
Guest
|
|
Posted: Sat Aug 27, 2005 4:55 pm |
|
|
would you happen to have a suggestion to perform a string compare against a string that is not allowed to changed? ie if(strcmp(guess, my permanent strig) then do something |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Aug 27, 2005 5:20 pm |
|
|
Look in the help file for strcmp(). You will find an example for strcat() that can be used for your problem. |
|
|
Guest
|
|
Posted: Sat Aug 27, 2005 5:49 pm |
|
|
Thank you for the suggestion. Please forgive me but I don't understand how concatenation can solve the problem? could you please give an example? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Aug 27, 2005 9:44 pm |
|
|
In CCS, the strcmp() function on works with strings that are in ram arrays.
So, if you have a constant string, you need to copy it into a ram array
by using the special CCS function, strcpy(). Then you can use strcmp().
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
const char Hello_string[] = "Hello"; // This string is in ROM
char temp[20];
//======================================
void main()
{
strcpy(temp, Hello_string); // Copy const string into ram array
// Now you can use strcmp() to compare temp to another array.
// Put your strcmp() code here.
while(1);
} |
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Aug 28, 2005 2:13 am |
|
|
Anonymous wrote: | Thank you for the suggestion. Please forgive me but I don't understand how concatenation can solve the problem? could you please give an example? |
It can't but if you look at the example and think just a bit you will see that you can apply the same principle but instead of strcat() do your strcmp()! |
|
|
Guest
|
|
Posted: Sun Aug 28, 2005 11:31 am |
|
|
Thanks,
Eric |
|
|
|