Simple string assignment problem

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Simple string assignment problem

507 Views
protoease
Contributor II

Banging my head against the wall on the following simple character string assignment problem:

 

char user_text[6];

 

// somewhere else in code:

user_text[] = {"text"};

 

Compiler throws up alarm on C1830: Modifiable lvalue expected.

 

What am I doing wrong?

 

I don't want to include string support as I can't support the burden size-wise.

 

Appreciate any help, I'm sure it is something silly and simple.

 

Thanks,

Aaron

Labels (1)
0 Kudos
1 Reply

218 Views
bigmac
Specialist III

Hello Aaron,

 

Your string assignment is not allowable in C.  With this format, a constant or variable may only be initialised, i.e. at the same time the constant or variable is defined.

 

To assign data to an array variable within a function, each element of the array woulld need to be individually written.

user_text[0] = 't';

user_text[1] = 'e';

user_text[2] = 'x';

user_text[3] = 't';

user_text[4] = 0;

 

To copy constant string data into the array variable, you will need to write your own function if you do not wish to include an existing library within your project.  Keep in mind that only the code size associated with the particular library functions that you use, will be added to your project.

 

Regards,

Mac

0 Kudos