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 support@ccsinfo.com

how to pass a string to function

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



Joined: 20 Oct 2007
Posts: 17
Location: coimbatore,india

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

how to pass a string to function
PostPosted: Thu Jul 17, 2008 6:20 am     Reply with quote

i need a help in passing a string to function..
in my application i'm using usart to send a string continuosly.
for ex..void usart(int *a); //function declaration
{
while(*a)
putc(*a++);
}

function call
usart("hello world");

it shows a error "attempting to create a pointer for constant"


but i can able to do this coding in other cross compilers like hitech.. how to solve this
_________________
with regards
vijay s
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Thu Jul 17, 2008 7:20 am     Reply with quote

CCS puts strings into ROM, while pointers only point into RAM. I know there are some options to force constants into RAM, but I'm not very familiar with them. However, I do know that CCS supports a language extension where strings are automatically passed character-by-character to functions, so:
Code:
void usart (int a)
{
  putc(a);
}
or even simply:
Code:
putc("hello world");
should do what you want.
_________________
Andrew
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 17, 2008 11:40 am     Reply with quote

If you use the following #device statement, then you can do it:
Code:
#device PASS_STRINGS=IN_RAM

See the post for an example:
http://www.ccsinfo.com/forum/viewtopic.php?t=34682&start=4
Guest








PostPosted: Fri Aug 01, 2008 8:10 am     Reply with quote

i want to send a starting and ending characters.
so i wrote a method

Code:
void mySend(char string)                                                       
  { 
 
   putc(0x3A);  // inform that this is the starting 
   putc(string);
   putc(0x0D);   //    inform that this is the end   
                   
}     
can called it like

mySend("hello");

the responce i got is

:h
:e
:l
:l
:o


but what i wanted is

:hello

it seems like the function has been called several times that is equal to the number of characters in the parameter.

how can get what i want?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Aug 01, 2008 10:23 am     Reply with quote

You need to read the CCS manual. There is a function that accepts
a pointer to a string, but it's not putc(). Please read the manual.

Also, please follow the links in previous posts. If you follow the link
in my previous post, you will find an example.
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