Jump to content

date isn't being displayed..

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
14 replies to this topic

#1
teensicle

teensicle

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
im trying to use the __DATE__ function and it just wont display the date...:cursing:

fprintf(fp,"Employee Information Generated on",__DATE__);


#2
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts
You need to either tell fprintf which format specifier to use when you pass __DATE__ as a parameter (%s)
   fprintf(fp, "Employee Information Generated on [COLOR="Red"]%s[/COLOR]\n" ,__DATE__);
Or you can utilize concatenation of adjacent string literals since __DATE__ resolves into a string literal.
   fprintf(fp, "Employee Information Generated on " __DATE__ "\n");


#3
teensicle

teensicle

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
ok the date now works

trying to display text file in the window using fgets but it doesn't work i only get a printf statement


int emp_view()
{
        char emp_name_f[500];
        char emp_name_l[500];
        char address[500];
        char email[500];
        int tel;
        int age;
        int trn;
        int v_id;

            FILE *fp;
            fp=fopen("EMP_DETAILS","r");

            if(fp == NULL)
            {
                printf("Error Report: File Access Error (ERROR CODE 312)\n");
                return 1;
            }
            else {
                printf("File Access Successfully.Payroll Sheet:\n\n");
                while(fgets(emp_name_f,500,fp)!=NULL)
                {
                    printf("%s",emp_name_f);
                }
                }
            fclose(fp);
}


#4
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts

teensicle said:

trying to display text file in the window using fgets but it doesn't work i only get a printf statement
If possible, copy-and-paste of your output is easier for me to work with than trying to be clairvoyant. For that matter, the same goes for the input.

An aside:
if ( fp == NULL )
{
   printf("Error Report: File Access Error (ERROR CODE 312)\n");
   return 1;
}
Are you familiar with perror?

#5
kmhosny

kmhosny

    Programmer

  • Members
  • PipPipPipPip
  • 133 posts
if the printf your getting is "Error..." then you might check the extension of the file you reading from, in you code it's without extension.
 fp=fopen("EMP_DETAILS","r");
maybe it needs a .txt or what ever the extension you have for your file
"Recursion is just a line of code"
-Karim Hosny-
My flickr

#6
teensicle

teensicle

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
ok that works... now the next thing i need to do is creating folders...

#7
kmhosny

kmhosny

    Programmer

  • Members
  • PipPipPipPip
  • 133 posts
well i didnt try to create folders using c\c++ before as i know that folder manipulation isnt well supported in c\c++, but when i need it create folders using system() call.
system("mkdir employees");
and in this case your file name in fopen will be
fopen("employees/emp_details","r");

"Recursion is just a line of code"
-Karim Hosny-
My flickr

#8
teensicle

teensicle

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
it makes the folder.. any other cool thing i could add to my program? :D its fo school...

#9
kmhosny

kmhosny

    Programmer

  • Members
  • PipPipPipPip
  • 133 posts
:) well i wanted to add a note that since your using folders and fopen now has the folder name before the file name as in fopen("test/test.txt","r"), take care not to use \ instead of / since this can be interpreted as special characters in formating the strings.
and if a directory already exists it will print "a directory already exists" to your console screen so you might want to handle that to.
"Recursion is just a line of code"
-Karim Hosny-
My flickr

#10
teensicle

teensicle

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
Would you mind me adding your name to my acknowledgment screen?

#11
kmhosny

kmhosny

    Programmer

  • Members
  • PipPipPipPip
  • 133 posts
:) i have no problem, but whats the acknowledgment screen
"Recursion is just a line of code"
-Karim Hosny-
My flickr

#12
teensicle

teensicle

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
here's ma entire payroll project could you test please...?

#include <stdio.h>

#include <stdlib.h>

#include <Windows.h>

#include <time.h>

#include <conio.h>


int emp_view()

{

        char emp_name_f[500];

        char emp_name_l[500];

        char address[500];

        char email[500];

        int tel;

        int age;

        int trn;

        int v_id;


            FILE *fp;

            fp=fopen("RP_FILES/EMP_DETAILS.txt","r");


            if(fp == NULL)

            {

                printf("Error Report: File Access Error (ERROR CODE 312)\n");

                return 1;

            }

            else {

                printf("File Access Successfully.Employee Information:\n");

                while(fgets(emp_name_f,500,fp)!=NULL)

                {

                    printf("%s",emp_name_f);

                }

                }

            fclose(fp);


                printf("PRESS ANY KEY TO RETURN TO MAIN MENU");


                    getch();

                    system("CLS");

                    first_menu();

}


int emp_menu()

{

        int change;



            printf("\t\t\t****Employeee Information Main Menu****\n\n\n\n\n");


            printf("==>Select One (1) To Add Employee Details\n\n");

            printf("==>Select Two (2) To View Employee Database\n\n");

            printf("==>Select Three (3) To Return To Main Menu\n\n\n");


            printf("ENTER SELECTION: ");

            scanf("%d", &change);


                    switch(change)


                    {


                    case 1: system("CLS"); emp_details();

                    break;

                    case 2: system("CLS"); emp_view();

                    break;

                    case 3: system("CLS"); first_menu();

                    default: printf("Please Select A Valid Option");


                    }

}


int emp_details()

{

     FILE *fp;

     fp=fopen("RP_FILES/EMP_DETAILS.txt", "a+");


        char emp_name_f[100];

        char emp_name_l[100];

        char address[100];

        char email[100];

        int tel;

        int age;

        int trn;

        int v_id;


     printf("\n\t\t\t****Employee Information Screen****\n\n");



     printf("\n\nPlease Enter Employee's First Name: ");

     scanf("%s",&emp_name_f);

     printf("\n----------------------------------------------------\n");

     printf("\nPlease Enter Employee's Last Name: ");

     scanf("%s",&emp_name_l);

     printf("\n----------------------------------------------------\n");

     printf("\nPlease Enter Employee's Address: ");

     scanf("%s",&address);

     printf("\n----------------------------------------------------\n");

     printf("\nPlease Enter Employee's Email: ");

     scanf("%s",&email);

     printf("\n----------------------------------------------------\n");

     printf("\nPlease Enter Employee's Telephone #: ");

     scanf("%d",&tel);

     printf("\n----------------------------------------------------\n");

     printf("\nPlease Enter Emplyee's Age: ");

     scanf("%d",&age);

     printf("\n----------------------------------------------------\n");

     printf("\nPlease Enter Employee's TRN#: ");

     scanf("%d",&trn);



            fprintf(fp,"----------------------------------------------------\n");

            fprintf(fp,"Employee Information Generated on: %s",__DATE__);

            fprintf(fp,"\n----------------------------------------------------\n");

            fprintf(fp,"\nEmployee's Name: %s %s\n",emp_name_f,emp_name_l);

            fprintf(fp,"\nEmployee's Address: %s\n", address);

            fprintf(fp,"\nEmployee's Email: %s\n",email);

            fprintf(fp,"\nEmployee's Telephone#: %d\n",tel);

            fprintf(fp,"\nEmployee's Age: %d\n",age);

            fprintf(fp,"\nEmployee's TRN#: %d\n",trn);

            fprintf(fp,"\n----------------------------------------------------\n\n");


     fclose(fp);


     system("CLS");


            printf("\n\n\tInformation Processed... Press Any Key To Return To Main Menu");


     getch();


    system( "CLS");


     first_menu();



}

int emp_add()

{

    FILE *fp;

    fp=fopen("RP_FILES/RP_PR.txt","a+");


     char emp_name_f[15];

     char emp_name_l[15];

     int emp_s_hrs;

     int am_phr;

     float total_payout_b4_tax;

     float total_payout_after_tax;

     float tax = 17.5;

     int o_time;

     int o_val = 2;

     int o_usr;

     int per_val = 100;


{

     printf("\n\t\t\t\tEmployee Maintenance Screen\n\n");// New Employee Screen

     printf("\n----------------------------------------------------\n");

     printf("\nPlease Enter Employee's First Name: ");// Asking User to enter Employee Name

     scanf("%s",&emp_name_f);// collecting student name from user

     printf("\n----------------------------------------------------\n");

     printf("\nPlease Enter Employee's Last Name: ");

     scanf("%s",&emp_name_l);

     printf("\n----------------------------------------------------\n");

     printf("\nPlease Enter Standard Hourly Work Week: ");// Asking User to enter Standard Hourly Work Week

     scanf("%d",&emp_s_hrs);// Storing Standar Employee Work Week

     printf("\n----------------------------------------------------\n");

     printf("\nPlease Enter Amount Per Hour: $");// Asking User to amount per hour

     scanf("%d",&am_phr);// Storing the amount per hour

     printf("\n----------------------------------------------------\n");

     printf("\nPlease Enter Over Time Hours (Enter 0 If None): ");

     scanf("%d",&o_usr);

}

     system("CLS");



                {

                        printf("\n----------------------------------------------------\n\n");


                        printf("Payroll Details For: %s %s\n", emp_name_f, emp_name_l);


                        printf("\n----------------------------------------------------\n\n");



                        total_payout_b4_tax = emp_s_hrs * am_phr;

                        printf("\nAmount Before Tax Is :$%.2f \n", total_payout_b4_tax);


                        total_payout_after_tax = total_payout_b4_tax - (tax / per_val * total_payout_b4_tax) ;

                        printf("\nAmount After Tax Is: $%.2f \n", total_payout_after_tax);


                        o_time = total_payout_after_tax + (o_val * o_usr);

                        printf("\nOver Time Value: $%d \n", o_time);


                        printf("\nTax Percentage: %.2f(percent)\n", tax);


                }



            fprintf(fp,"\nPayroll Report Generated On: %s"__DATE__);

            fprintf(fp,"\n----------------------------------------------------\n");

            fprintf(fp,"\nPayroll Details For: %s %s\n",emp_name_f, emp_name_l);

            fprintf(fp," \nAmount Befor Tax: $%.2f\n", total_payout_b4_tax);

            fprintf(fp,"\nAmount After Tax: $%.2f\n", total_payout_after_tax);

            fprintf(fp,"\nTax Percentage: %.2f\n", tax);

            fprintf(fp,"\n\Over Time: $%d\n", o_time);


            fprintf(fp,"\n----------------------------------------------------");//separator for each payout

fclose(fp);


printf("\n----------------------------------------------------\n");

printf("Data Hase Been Successfully Copied\n");

printf("----------------------------------------------------\n\n");

printf("\t\t\tPress Any Key To Return To Main Menu\n\n");


    getch();


    system("CLS");


    first_menu();


}


int view_payroll()

{

      char emp_name[500];//Variable to store Employees name

      int emp_s_hrs[5];//Variable to store standard work hrs

      int am_phr[10];//Variable to store ammount per hour

      int tax;

      float total_payout_b4_tax = 0; //Variable to store total owed before tax

      float total_payout_after_tax = 0;


            FILE *fp;

            fp=fopen("EMP_DETAILS.txt","r");


            if(fp == NULL)

            {

                printf("Error Report: File Access Error (ERROR CODE 312)\n");

                return 1;

            }

            else {

                printf("File Access Successfully...Employee Information:\n\n");

                while(fgets(emp_name,1000,fp)!=NULL)

                {

                    printf("%s",emp_name);

                }

                }

            fclose(fp);


}


int menu_main()


{

    int selection;

    printf("\n\t\t****Welcome To The Right Price Payroll Center****\n\n\n");


    printf("--------------------------------------------\n");

    printf("==> To Add A New Employee Press One (1)\n");

    printf("--------------------------------------------\n");

    printf("==> To View Payroll Payouts press Two (2)\n");

    printf("--------------------------------------------\n");

    printf("==> To View Employee Details (3)\n");

    printf("--------------------------------------------\n");

    printf("==> Return To Main Menu (4)");

    printf("\n--------------------------------------------\n\n");

    printf("ENTER SELECTION:");

    scanf("%d", &selection);


        switch(selection)

           {

                         case 1:system("CLS");emp_add();

                         break;

                         case 2:system("CLS");view_payroll();

                         break;

                         case 3: system("CLS");emp_view();

                         break;

                         case 4:system("CLS");first_menu();

                         default: printf("Please Select A Valid Option");

           }


}


void main()

{


    system("mkdir RP_FILES");


char choice;

    do

       {

       first_menu();

       //printf("\nReturn To The Main Menu? y/n: \n");

       //scanf("%c",&choice);

       }

    while(choice == 'y');

         if(choice =='n')

        {exit(0);}


}


int help_menu()

{

    int selection;


   printf("PAGE NOT CONFIGURED\n\n");

   printf("PRESS ANY KEY TO RETURN TO THE MAIN MENU");


   getch();

   system("CLS");

   first_menu();



}


int first_menu()

{

        int select;


        SYSTEMTIME str_t;

        GetSystemTime(&str_t);


        printf("\t\t******************************************\n");

        printf("\t\t** Right Price Wholesale Payroll System **\n");

        printf("\t\t**         By Darien Ruddock            **\n");

        printf("\t\t**        Version: 1.0 Build 1          **\n");

        printf("\t\t**           Date:%d/%d/%d             **\n",str_t.wYear,str_t.wMonth,str_t.wDay);

        printf("\t\t**                                      **\n");

        printf("\t\t**                                      **\n");

        printf("\t\t**                                      **\n");

        printf("\t\t**                                      **\n");

        printf("\t\t******************************************\n\n\n");



        time_t mytime;

		mytime = time(NULL);

		printf(ctime(&mytime));



		printf("\nSelect One(1) For Employee Maintenance Screen\n\n");

		printf("Select Two(2) For Employee Information\n\n");

		printf("Select Three(3) For Product Information\n\n");

		printf("Select Four(4) For Help Menu\n\n");

		printf("Select Four (5) To Exit System\n\n\n");

		printf("ENTER SELECTION:");

		scanf("%d", &select);



        switch(select)


            {


                    case 1:system("CLS");menu_main();

                    break;

                    case 2:system("CLS");emp_menu();

                    break;

                    case 3:system("CLS"); info_menu();

                    break;

                    case 4: system("CLS"); help_menu(0);

                    break;

                    case 5: system("CLS"); exit(0);

                    default: printf("Please Select A Valid Option");

            }


return 0;

}


int info_menu()

{


    printf("\n\n\n\n\t\t**************************************************\n");


    printf("\t\t\tDeveloped By: Darien Ruddock\n\n");


    printf("\t\t\tFrom: St. Jago High School\n\n");


    printf("\t\t\tVersion: 1.0 Build 1\n\n");


    printf("\t\t\tContact Information: ruddpe@hotmail.com\n\n");


    printf("\t\t\tContributors: Mr. Brown, Mr. Edwards, kmhosny(codecall.net)\n\n");


    printf("\t\t**************************************************\n\n\n");


    printf("\t\t\tPress Any Key To Return To Main Menu");


    getch();


    system("CLS");


    first_menu();


}