1

I am trying to code a program that shows the Easter day when the user inputs the year between 1991 and 2099. All are good but when I am trying to run the program, it says there is an error: assignment to expression with array type. How can I fix this? and what is the wrong with my code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
char month[50];
int year, day;
printf("Please enter a year between 1990 and 2099: ");
scanf("%d", &year);


int a = year-1900;
int b = a%19;
int c = (7*b+1)/19;
int d = (11*b+4-c)%29;
int e = a/4;
int f = (a+e+31-d)%7;
int g = 25 - (d + f);

if (g <= 0 )
{
    month = "March";
    day = 31 + g;
}
else
{
    month = "April";
    day = g;
}
    printf("The date is %s %d", month, day);

}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335

1 Answers1

1

Arrays do not have the assignment operator. Arrays are non-modifiable lvalues.

To change the content of an array use for example the standard string function strcpy.

#include <string.h >

//...

strcpy( month, "March" );

An alternative approach is to declare the variable month as a pointer. For example

char *month;

or (that is better)

const char *month;

In this case you may write

month = "March";
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
  • "lvalue" literally means "can be used on the LHS of an assignment". Did you mean "rvalue"? – ikegami Oct 25 '21 at 18:08
  • @ikegami No according to the C Standard arrays are non-modifiable lvalues. – Vlad from Moscow Oct 25 '21 at 18:09
  • Ok, but how odd – ikegami Oct 25 '21 at 18:15
  • @ikegami The origin of the terms refers to where they appear in assignments, language details sometimes make those meanings not apply. An lvalue is an expression that denotes a memory location, while an rvalue is a value without an associated location (it can be a temporary value from an expression). – Barmar Oct 25 '21 at 18:58