i am new in this

Discussion in 'Meet and Greet' started by hamza.awaly, Apr 28, 2012.

  1. hamza.awaly

    hamza.awaly New Member

    Joined:
    Apr 28, 2012
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    beirut lebanon
    hiii, i am so proud to be on of you , i am really happy to learn more and more about c language and i have assignment . and i would like to help me please.
    i don't have enough time so plzz.

    the question is :
    Write a C program the print the calendar of certain month. This can be done by asking the user to enter the starting day of the month and the number of days in these months.


    thank you.
    kissesxoxoxo
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    Not really tested, but maybe it works... I'm too sleepy to argue with it any longer. :biggrin:

    Code:
    #include <stdio.h>
    #include <string.h>
    
    char *CAL[] = { "sun", "mon", "tue", "wed", "thu", "fri", "sat" };
    
    int main(void) {
    
       char input[] = "mon 31";
       int i, offset, ndays;
    
       sscanf(input + 3, "%d", &ndays);   
    
       puts("  S   M   T   W   T   F   S \n");
    
       for(i=0; i < 7; ++i)
          if(strncmp(input, CAL[i], 3) == 0)
    	     break;
    	
       offset = i;		 
       i = 0;
    
       while(i < offset) { 
          printf("    ");
    	  ++i;
       }
    
       i = 1;
    
       while(i <= ndays) {
          if((i + offset - 1) % 7 == 0)
    	     putchar('\n');
    
          printf(" %2d ", i);
    	  ++i;
       }
    
       puts("\n\ndone...");
    
       return 0;
    }
     
  3. hamza.awaly

    hamza.awaly New Member

    Joined:
    Apr 28, 2012
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    beirut lebanon
    actually isn't what i want :) thxx for ur help dear
     
  4. hamza.awaly

    hamza.awaly New Member

    Joined:
    Apr 28, 2012
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    beirut lebanon
    Write a C program the print the calendar of certain month. This can be done by asking the user to enter the starting day of the month and the number of days in these months plzzzzzz try again :)
     
  5. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    Write a C program the print the calendar of certain month. This can be done by asking the user to enter the starting day of the month and the number of days in these months.

    I don't follow what you're asking.

    What are "calendar of certain month" and "starting day of month" supposed to be in terms of a program? If a user enters those parameters, what is he or she being asked to enter? A text representation for the day of the week, a numerical representation of the day, etc.

    Similarly, what month is supposed to be printed and for what year? All months having X number of days? The first month having X days, etc

    There isn't enough information provided to determine how to go about finding a possible solution... well for me at least. :)

    [edit]
    shabbir was holding out . I like that - thanks.

    fflush(stdin) - naughty naughty. :D
    [/edit]
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice