struct and "char" assignement

General discussion on mikroC.
Post Reply
Author
Message
vouilloz_d
Posts: 9
Joined: 07 Apr 2005 21:44
Location: Switzerland

struct and "char" assignement

#1 Post by vouilloz_d » 13 May 2005 11:41

I will like to use a stucture in my program, but i do not manage to assign a value in a table of "char"
Error:Assigning to non-lvalue[]

Code: Select all

struct Menu{
  char Num;
  char Nom[20];
}Principal[2], Config[3];

void main() {
  Principal[0].Num = "1";
  Principal[0].Nom = "Config"; // this line create a error

}

nikola
mikroElektronika team
Posts: 137
Joined: 03 Aug 2004 12:44
Contact:

Re: struct and "char" assignement

#2 Post by nikola » 13 May 2005 12:21

According to ANSI C, array is not an lvalue, so you cannot perform the stated assignment. It should work if you declare Nom as pointer to char:

Code: Select all

struct Menu {
  char Num;
  char *Nom;
} Principal[2], Config[3];
-

vouilloz_d
Posts: 9
Joined: 07 Apr 2005 21:44
Location: Switzerland

#3 Post by vouilloz_d » 13 May 2005 17:37

Many thanks Nikola, thats functions very well.

vouilloz_d
Posts: 9
Joined: 07 Apr 2005 21:44
Location: Switzerland

#4 Post by vouilloz_d » 14 May 2005 12:09

Now, i have an error which this product when i want to pass a structure to a procedure

Error Message:
StrUni_Size: argument not found
Bank not found: StrUni_Size

Code: Select all

struct Menu {
   char Num;
   char *Nom;
} Principal[2];

void Display_Line(struct Menu Select);

void main() {
Principal[1].Nom = "Diag";
Principal[1].Num = "1";

Display_Line(Principal[1]);

}

void Display_Line(struct Menu Select) {
  Delay_ms(500);
}

User avatar
rajkovic
mikroElektronika team
Posts: 694
Joined: 16 Aug 2004 12:40

#5 Post by rajkovic » 14 May 2005 20:57

vouilloz_d wrote:

Code: Select all

struct Menu {
   char Num;
   char *Nom;
} Principal[2];

void Display_Line(struct Menu Select);

void main() {
Principal[1].Nom = "Diag";
Principal[1].Num = "1";

Display_Line(Principal[1]);

}

void Display_Line(struct Menu Select) {
  Delay_ms(500);
}
This is our bug (passing struct by value to function). we will solve it.
For now please use pointer to struct as workaround

Code: Select all

 void Display_Line(struct Menu* Select) {
  Select->Num = '1';
  Delay_ms(500);
}
Note that

Code: Select all

Principal[1].Num = "1";
make string that has '1' and 0 as terminator
put pointer to that string to Num

is not same as

Code: Select all

 Principal[1].Num = '1'; 
this way you get ascii code of 1 in Num

Post Reply

Return to “mikroC General”