CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

#define a string

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








#define a string
PostPosted: Sat Aug 27, 2005 3:40 pm     Reply with quote

Is this permitted? #define string (char*)"hi"

If not, any suggestions?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Sat Aug 27, 2005 4:43 pm     Reply with quote

pointers to constants are not allowed.
Guest








PostPosted: Sat Aug 27, 2005 4:55 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Sat Aug 27, 2005 5:20 pm     Reply with quote

Look in the help file for strcmp(). You will find an example for strcat() that can be used for your problem.
Guest








PostPosted: Sat Aug 27, 2005 5:49 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Aug 27, 2005 9:44 pm     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Sun Aug 28, 2005 2:13 am     Reply with quote

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








PostPosted: Sun Aug 28, 2005 11:31 am     Reply with quote

Thanks,

Eric
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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