CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Help!

  1. #1
    Join Date
    Feb 2008
    Posts
    24

    Help!

    So I'm supposed to create a program that lists all the dates from starting date to ending date that is input by the user. I got the program to compile.. But when I open the .txt file that is supposed to contain the output it is empty... and I can't really figure out where I went wrong... Can someone please help me out?!
    Thanks!


    Code:
    #include <stdio.h>
    
    int main()
    {
    
    FILE *test;
    int day, startingDay, endingDay;
    int year, startingYear, endingYear;
    int month, startingMonth, endingMonth;//can save the months as numbers, jan=1 etc..
    int x=0;
    
    test = fopen ("test.txt", "w");
    
    printf("Please enter the StartingDate in the form MM/DD/YYYY\n");
    scanf("%d/%d/%d", &startingMonth, &startingDay, &startingYear);
    
    printf("Please enter the EndingDate in the form MM/DD/YYYY\n");
    scanf("%d/%d/%d", &endingMonth, &endingDay, &endingYear);
    
    //ask user for starting date and ending date
    //save as startingYear, endingYear, startingDay, endingDay, etc...
    
    
    for (year = startingYear; year < endingYear; year++)
    {
    
    for (month = startingMonth; month < 12; month++)
    {
    
    for (day = startingDay; day <= x; day++)
    {
    
    
    switch(month)
    {
    case 1:
    x=31;
    fprintf(test, "January %d, %d",day, year);
    
    
    case 2:
    x=28;
    fprintf(test, "February %d, %d",day, year);
    
    
    case 3:
    x=31;
    fprintf(test, "March %d, %d",day, year);
    
     
    case 4:
    x=30;
    fprintf(test, "April %d, %d",day, year);
    
    
    case 5:
    x=31;
    fprintf(test, "May %d, %d",day, year);
    
    
    case 6:
    x=30;
    fprintf(test, "June %d, %d",day, year);
    
    
    case 7:
    x=31;
    fprintf(test, "July %d, %d",day, year);
    
    
    case 8:
    x=31;
    fprintf(test, "August %d, %d",day, year);
    
    
    case 9:
    x=30;
    fprintf(test, "September %d, %d",day, year);
    
    
    case 10:
    x=31;
    fprintf(test, "October %d, %d",day, year);
    
    
    case 11:
    x=30;
    fprintf(test, "November %d, %d", day, year);
    
    case 12:
    x=31;
    fprintf(test, "December %d, %d", day, year);
    
    }
    
    
    if ((month = endingMonth) && (day = endingDay) && (year = endingYear)){
            break;//exit all loops and finish program
            }
    }
    startingDay = 0;
    }
    startingMonth = 0;
    }
    
    fclose(test);
    return 0;
    }

  2. #2
    Join Date
    Feb 2008
    Posts
    27

    Re: Help!

    why not just do it with an fstream?
    Code:
    #include <fstream>
    
    ...
    
    ofstream outfile;
    outfile.open("name.txt");
    Also if you're running vista you must manually locate the app in the debug dir and run in admin mode for any file interaction to work properly.

  3. #3
    Join Date
    Feb 2008
    Posts
    24

    Re: Help!

    Quote Originally Posted by aosmith
    why not just do it with an fstream?
    Code:
    #include <fstream>
    
    ...
    
    ofstream outfile;
    outfile.open("name.txt");
    Also if you're running vista you must manually locate the app in the debug dir and run in admin mode for any file interaction to work properly.
    I get the error:
    P666.c:2: fstream: No such file or directory
    ... and im not sure how to locate the app in the debugger directory ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured