View previous topic :: View next topic |
Author |
Message |
vijay s
Joined: 20 Oct 2007 Posts: 17 Location: coimbatore,india
|
how to pass a string to function |
Posted: Thu Jul 17, 2008 6:20 am |
|
|
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
|
|
Posted: Thu Jul 17, 2008 7:20 am |
|
|
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
|
|
|
Guest
|
|
Posted: Fri Aug 01, 2008 8:10 am |
|
|
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
|
|
Posted: Fri Aug 01, 2008 10:23 am |
|
|
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. |
|
|
|