Monday, May 24, 2010

C Programming error message?

C Programming error?





Hi, just started programming in C for uni.


Here's the relevant part of the program:





#define SIZE 100


{ int day_n, dayn;


char day[SIZE];


...


day_n = %26lt;some function%26gt;;


dayn = day_n%7;





if (dayn==0) day="Saturday";


else if (dayn==1) day="Sunday";


%26lt;etc%26gt;





printf("The day is a %c\n", day)


}





I keep getting error for each line with day in it:


left operand must be modifiable lvalue: op "="


I don't know what this means, or how to fix it, please help!


(I know this isn't the best way of writing it, but I can't be bothered to use a switch statement now!)

C Programming error message?
You can't copy a string like that.


look up strcpy().





Or, do something like this.


if(dayn==0)


printf("The day is Saturday")


if(dayn==1)


printf("The day is Sunday")
Reply:day_n and dayn are integers





enum {SATURDAY,SUNDAY...FRIDAY};





if(day_n == SATURDAY) // the enumerated value of SATURDAY is 0


strcpy(day,"SATURDAY"); // NOTE quoted string is not an integer


if(day_n == SUNDAY) // the enumerated value of SUNDAY is 1


strcpy(day,"SUNDAY");





etc...





?cant be bothered with a switch?





tm_horton@yahoo.com as I can help


No comments:

Post a Comment