'cannot assign array type objects' error

Status
Not open for further replies.

ADGAN

Full Member level 5
Joined
Oct 9, 2013
Messages
295
Helped
4
Reputation
8
Reaction score
4
Trophy points
18
Activity points
1,837
Hi! This is a part of my code which I'm writing in MPLAB C18. It gives the following error.

Error [1153] cannot assign array type objects
Error [1102] cannot assign to 'const' modified object
Error [1131] type mismatch in assignment

I don't know how to correct this error? Pls help.

Code:
char tnum[4],txt[];

void Zero_Fill(char *value) { // fill text representation
if (value[1] == 0) { // with leading zero
value[1] = value[0];
value[0] = 48;
value[2] = 0;
}
}

void rtrim(unsigned char* input){
  while (*input != 0)
    input++;
  input--;
  while (*input == ' '){
    *input = 0;
    input--;
  }
}

btoa(day,tnum);
txt = rtrim(tnum);
Zero_Fill(txt);
LCD_TextOut(3,7,txt);
 

Is it asking too much if you show which code lines are causing the errrors?

Obviously, a void function don't has a return value that could be assigned to a variable
Code:
txt = rtrim(tnum);

A variable definition "char txt[];" doesn't make sense. It's not a pointer definition and it doesn't allocate storage. The construct name[] is only meaningful for initialized arrays, external declaration or formal function parameters.
 

Sorry forgot to mention that. It is the 'txt = rtrim(tnum);' line that makes the error.
 

I don't understand what should I do?
 

I don't understand what should I do?
Respect the C syntax rules. If you want output from a function, specify a return type. Or don't try to assign anything to a void function.


P.S.:
In your code, rtrim() modifies the input string tnum. So what you probably want to do is to to use tnum instead of txt.
 
Last edited:

Ok I understood what you telling. I changed it & seems to be ok.

- - - Updated - - -

I have made a mistake. rtrim is a function used in MikroC to trim the trailing space from array. I have written a function for this and its incompatible for this. Do you know any function that I can do this in MPLAB?
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…