Thread: printing days for a particular month

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    printing days for a particular month

    Hey guys just wondering if someone can check my program out iv attached the files its the cal.c program. Im trying to print the days in a month if its 31 days in that month i want it to print the sequence from 1 2 3 4 etc etc to 31

    eg if you type cal 1 2006 in unix

    January

    1 2 3 4 5 6 7
    8 9 10 11 12
    etc etc

    how can i go through the 31 days then print them for each month

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    Code:
    display_month(int st,int n){
    printf("\ns  m  t  w  t  f  s" );
    printf("\n");
    int c= st;
    for(int j=1;j<c;j++)printf("   ");
    for(int j =1;j<=n;j++){
    if(j>9)printf("%d ",j); else
    printf("%d  ",j);
    c++;
    if(c==8){c=1;printf("\n");}
     }
    };
    try along these lines,
    st determines the starting of the month, it is 1 if month starts with a sunday,2 if month starts with a monday and so on.
    n is the number of days in the month.

  3. #3
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    calendar

    Hey guys could u check out my program again stil a little confused about getting the days for each month for the calendar?

    its not working for some reason the way it should for some reason
    mon tue wed thu fri sat sun
    1 2 3 4 5 6 7
    etc etc

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well something like
    Code:
    int daysInMonth[] = { 31, 28, };
    char *monthNames[] = {
      "January",
      "February",
    };
    Extended of course to fill in the other 10 entries yourself.

    Then you can do
    Code:
    printf( "%s", monthNames[month-1] );

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting the next day's day, month, year etc
    By underthesun in forum C Programming
    Replies: 3
    Last Post: 02-17-2005, 07:43 AM
  2. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM
  3. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM
  4. cant get code to work
    By duffy in forum C Programming
    Replies: 13
    Last Post: 10-20-2002, 05:23 AM
  5. Printing weekday
    By sworc66 in forum C Programming
    Replies: 12
    Last Post: 09-13-2002, 07:03 AM