EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / C program to print calender to a file

C program to print calender to a file

|

Miscellaneous › Others › C program to print calender to a file

  • This topic has 0 replies, 1 voice, and was last updated 14 years, 11 months ago by Rakesh Bute.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • January 12, 2011 at 2:42 am #534
    Rakesh Bute
    Participant

     Hi, 

     I’ve tried to make a C program to print calender to a specific file, which looks as follows—-

     

    //


    cut below here and paste in your C editor and compile


    //6:53 PM 12/30/2009

    //AUTHOR-Rakesh Bute

    #include<stdio.h>

    //


    #define stdday 6

    #define stdyr  2000

    //


    void main()

    { unsigned int y[3];

    unsigned int m,d,dl,num;

     

    char *ch,ca,dp[256];

    char Header[36],*Months[12];

    FILE *fp;

    //


    beig:

    clrscr();

    //


    puts(“nWould you change O/P path::”);

    ca=getch();

    //


    if(ca==’y’||ca==’Y’)

    goto change;

     

    fp=fopen(“C:/Calp.txt”,”r”);

    //


    if(fp==NULL)

    {   change:

    fp=fopen(“C:/Calp.txt”,”w”);

    puts(“nEnter thefile path::  “);

    gets(ch);

    fputs(ch,fp);

    fclose(fp);

    goto beig;

    }

    //


    fgets(dp,sizeof(dp),fp);

     

    fclose(fp);

    ch=dp;

     

    fp=fopen(ch,”a”);

    //


    printf(“nEnter start year:: “);

    scanf(“%ld”,&y[1]);

     

    printf(“nEnter end   year:: “);

    scanf(“%ld”,&y[2]);

     

    printf(“nPrint in screen too::”);

    fflush(stdin);

    ca=getch();

    clrscr();

    //


    Months[0] = “nJANUARY  “;

    Months[1] = “nFEBRUARY “;

    Months[2] =”nMARCH    ” ;

    Months[3] =”nAPRIL    ” ;

    Months[4] =”nMAY      ” ;

    Months[5] =”nJUNE     ” ;

    Months[6] =”nJULY     ” ;

    Months[7] =”nAUGUST   ” ;

    Months[8] =”nSEPTEMBER” ;

    Months[9] =”nOCTOBER  ” ;

    Months[10]=”nNOVEMBER ” ;

    Months[11]=”nDECEMBER ” ;

    strcpy(Header,”nnn SUN MON TUE WED THU FRI SATnn”);

    //


    dl=stdday;

    for(y[0]=stdyr;y[0]<=y[2];y[0]++)

    {

    //


    for(m=1;m<=12;m++)

    { switch(m)

    { case 1 :num=31;break;

    case 2 :num= 0;break;

    case 3 :num=31;break;

    case 4 :num=30;break;

    case 5 :num=31;break;

    case 6 :num=30;break;

    case 7 :num=31;break;

    case 8 :num=31;break;

    case 9 :num=30;break;

    case 10:num=31;break;

    case 11:num=30;break;

    case 12:num=31;break;

    }

     

    if(y[0]>=y[1])

    { printf(“%s”,Months[m-1]);

    fprintf(fp,”%s”,Months[m-1]);

    }

    //


    if(y[0]>=y[1])

    { printf(“%19d”,y[0]);

    fprintf(fp,”%19d”,y[0]);

    }

    //


    if(num==0)                                  // The lip year logic 

    {  if(y[0]%400==0)                     //

    num=29;

    else if(y[0]%100==0)

    num=28;

    else if(y[0]%4==0)

    num=29;

    else if(y[0]%4!=0)

    num=28;

    }

    //


    if(y[0]>=y[1])

    {

    printf(“%s”,Header);

    fprintf(fp,”%s”,Header);

    }

    //


    if(y[0]>=y[1])

    for(d=dl;d>0;d–)

    { printf(”    “);

    fprintf(fp,”    “);

    }

    //


    for(d=1;d<=num;d++)

    { if(y[0]>=y[1])

    { printf(“%4d”,d);

    fprintf(fp,”%4d”,d);

    }

    //


    if(((d+dl)%7==0)&&(y[0]>=y[1]))

    { printf(“n”);

    fprintf(fp,”n”);

    }

    } //day close

    //


    dl=(d+dl-1)%7;

     

    if(y[0]>=y[1])

    { printf(“nn”);

    fprintf(fp,”nn”);

    }

    //


    if(y[0]>=y[1]&&(ca==’y’||ca==’Y’))

    getch();

    }                                       //month close

    if(y[0]==y[1]+100)

    { puts(“nnThis program prints dates upto”);

    puts(“”LOWERLIMIT+100YR” onlyb”);

    break;

    }

    ch=NULL;

    } //year close

    //


    fclose(fp);

    puts(“nnRedo calculations?  “);

    fflush(stdin);

    ca=getch();

    //


    if(ca==’y’||ca==’Y’)

    goto beig;

    //


    getch();

    }

     

     

    //


    the program ends here


     

     

     

     

    Thank you…….

     

  • Author
    Posts
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • I am ready to move from electrical and electronics field but confused where ? December 6, 2025
  • Funny Images Thread! December 6, 2025
  • replacing an absolete component of converter December 6, 2025
  • UPS for elevator December 6, 2025
  • anyone recognizes this laser diode? December 6, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise