How is this done without being too lengthy??
How is this done without being too lengthy??
This isnt right???
Code:#include <stdio.h> #include <string.h> #define LSIZE 15 void week(); int main() { char today[LSIZE]; enum week {Saturday = 0, Sunday = 0, Monday = 1, Tuesday, Wednesday, Thursday, Friday}; printf ("Enter the day of the week (eg. Wednesday) :\n"); week (today); sscanf ("%s", today); if (today == Sunday || Saturday) printf("You can rest today"); else printf("GO TO WORK!!"); return 0; } void week(char strng[]) { int i = 0; char c; while (i < (LSIZE-1) && (c = getchar()) !='\n') { strng[i] = c; i++; } strng[i] = '\0'; }
Comparison of strings is done with the string comparison function strcmp.
This is beyond what I have learned so far. Can someone give me an example or a little more help please??
Always a shame to skip classes.This is beyond what I have learned so far.
If this is homework, that means you have a book; you should be able to look up "strcmp" in your index. You also need to read the chapter on functions, the chapter on getting input from the user, and the chapter on logical operators (&& and || and the like).
Couple of things.. you should probably call week(string) after you scan the value using scanf
then do something like:
also think about what should happen if the user enters it in all caps, or with a lowercase first letter...Code:if (!(strcmp(today, "Saturday") || !(strcmp(today, "Sunday")) { !!! then it's a weekend } else if(!strcmp(today, "Moday"...) { !!!... } else { !!! printerror }
Last edited by dinjas; 04-19-2008 at 10:03 PM. Reason: left off a paren
straight off the heap