View previous topic :: View next topic |
Author |
Message |
Guest
|
How to use a string as param in a function |
Posted: Wed Apr 09, 2008 1:59 am |
|
|
Problem to use a function to transfer a string?
Smal ex. to show the problem.
Code: | void disp_print(st???){
printf(mydev,"%s",st);
}
void main{
//test 1 working direct printing
printf(mydev,"testing"); //working and string is placed in ROM.
//test 2
disp_print("testing"); //how to do this?
}
|
|
|
|
Matro Guest
|
|
Posted: Wed Apr 09, 2008 2:07 am |
|
|
Parameter type is "char*".
Matro |
|
|
Matro Guest
|
|
Posted: Wed Apr 09, 2008 2:10 am |
|
|
Notice that for this example to work properly, you have to add :
Code: |
#device PASS_STRINGS = IN_RAM
|
in your code.
Matro |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Wed Apr 09, 2008 6:27 am |
|
|
Or alternatively: Code: | void disp_print(char c){
fputc(c, mydev);
}
void main{
disp_print("testing");
} | The compiler will automatically create the loop to call disp_print once for each character in the string. _________________ Andrew |
|
|
|