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

string of array

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



Joined: 01 Dec 2019
Posts: 2

View user's profile Send private message

string of array
PostPosted: Sun Dec 01, 2019 4:57 am     Reply with quote

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: 19506

View user's profile Send private message

PostPosted: Sun Dec 01, 2019 10:57 am     Reply with quote

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

View user's profile Send private message

Ttelmah
PostPosted: Mon Dec 02, 2019 6:31 am     Reply with quote

Thank you very much for your help.
It works well.

Have a nice day!
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