Thread: Need Help

  1. #16
    Registered User
    Join Date
    Apr 2008
    Posts
    14
    How is this done without being too lengthy??

  2. #17
    Registered User
    Join Date
    Apr 2008
    Posts
    14
    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 ("&#37;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';
    		
    }

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Comparison of strings is done with the string comparison function strcmp.

  4. #19
    Registered User
    Join Date
    Apr 2008
    Posts
    14
    This is beyond what I have learned so far. Can someone give me an example or a little more help please??

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    This is beyond what I have learned so far.
    Always a shame to skip classes.

    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).

  6. #21
    Registered User dinjas's Avatar
    Join Date
    Feb 2005
    Location
    Vancouver, Washington
    Posts
    40
    Couple of things.. you should probably call week(string) after you scan the value using scanf
    then do something like:
    Code:
    if (!(strcmp(today, "Saturday") || !(strcmp(today, "Sunday")) {
       !!! then it's a weekend
    } else if(!strcmp(today, "Moday"...) {
       !!!...
    } else {
       !!! printerror
    }
    also think about what should happen if the user enters it in all caps, or with a lowercase first letter...
    Last edited by dinjas; 04-19-2008 at 10:03 PM. Reason: left off a paren
    straight off the heap

Popular pages Recent additions subscribe to a feed