|
|
View previous topic :: View next topic |
Author |
Message |
bruceryu
Joined: 01 Dec 2019 Posts: 2
|
string of array |
Posted: Sun Dec 01, 2019 4:57 am |
|
|
Hello,
I have a problem with below code.
Please advise how to solve it.
Thanks in advance!
Code: |
void locate(const char cursor_x, const char cursor_y) {
char stream[4] = {0x1b, 0x4c, cursor_x, cursor_y};
}
|
<error message>
Line 112(19,23): Expecting an identifier
Line 112(32,33): Expecting a declaration
Line 112(53,54): Expecting an =
Line 112(55,56): Expecting a declaration
Line 113(34,42): Undefined identifier cursor_x
Line 113(44,52): Expecting a (
Line 114(25,26): Expecting an identifier |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19543
|
|
Posted: Sun Dec 01, 2019 10:57 am |
|
|
There are several issues:
First you cannot use 'const' as a variable declarator in a function.
const in CCS C, means a value stored in ROM. The value can be passed to
a function, but it is not then a 'const'.
This is different from the ANSI use of 'const', where it means a variable
in RAM, which is protected from being changed.
So get rid of the const declarations.
Then the big issue is that the assignment of 'stream', is done at compile
time. At compile time, neither cursor_x or cursor_y have values.
To assign values passed to the function, these have to be done at run-time:
Code: |
void locate(char cursor_x, char cursor_y) {
char stream[4]={0x1b, 0x4c, 0,0};
stream[2]=cursor_x; //runtime assignment of variable
stream[3]=cursor_y;
}
|
|
|
|
bruceryu
Joined: 01 Dec 2019 Posts: 2
|
Ttelmah |
Posted: Mon Dec 02, 2019 6:31 am |
|
|
Thank you very much for your help.
It works well.
Have a nice day! |
|
|
|
|
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
|