Good day everyone.

I am back from some previous months of extensive schoolwork.

I am creating now a payroll application,
but I think there's something wrong in my code,
because it created an output that's not my intended output.

Wait, guys, I'm confused. Is this appropriate for a C forum although
I use C language in my code? Because I'm using a C++ Compiler,
my assumption is to post it here in C Forum.
Well it's okay if someone moves this thread in C++ area.
I'm just currently a newbie in such forums.

Here's my code:

/* My Payroll System /
/
----------------------------------------------*/
// Start of file.

//Include Libraries

include<stdio.h>

include<conio.h>

include<string.h>

include<dos.h>

include<time.h>

include<iostream.h>

//Defines Functions

define g gotoxy

define p printf

define s scanf

define fp fprintf

define fs fscanf

//Pointer Chars for Time-in and Time-out
char *day[5]={"Monday","Tuesday","Wednesday","Thursday","Friday"};

//Variables with Arrays
int time_in[2];
int time_out[2];
char empna[30];
char empmidna[15];
char emplastna[30];
char empcode[30];
char date[30];
char min[5];
char searchempcode[30];

//Variables
int found, x;
int level;
int twhrs=0;
float rinc;
float srate=0;

//File Operations
FILE *empfile;
FILE *dtrfile;

//SUBROUTINE: Prints the current time (Optional)
void printtime()
{
struct time t;

gettime(&t);                                 
{
g(60,24);p("[ %2d:%02d:%02d.%02d ]\n",
    t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
}

}

//SUBROUTINE: Header Bar Message (Optional)
void showmsg()
{
g(22,2);p("Spectre Reviewals Examination Company");g(25,3);p("Assessment : Payroll System");
g(1,4);p("[------------------------------------------------------------------------------]\n");
}

//SUBROUTINE: Read File Operations
void readfile()
{
fs(empfile, "%s", &empna);
fs(empfile, "%s", &empmidna);
fs(empfile, "%s", &emplastna);
fs(empfile, "%s", &empcode);
fs(empfile, "%d", &level);
}

//SUBROUTINE: Write File Operations
void writefile()
{
showmsg();
printtime();
fp(dtrfile, "%s : ", empcode);
for(x=0;x<5;x++)
{
fp(dtrfile, " %d%s ", time_in[x], min[x]);
fp(dtrfile, " %d%s ", time_out[x], min[x]);
}
}

//SUBROUTINE: File and Program Process Operations
void process_data()
{
clrscr();
showmsg();
printtime();
g(13,6);p("Enter the login and logout time for the days described.");
g(19,7);p("Clock times must be in military format.");
g(22,8);p("(Example: Eight o' clock = 0800) \n");
for(x=0;x<5;x++)
{
p("\n Time in for the day of %s: ", day[x]);
s("%d%s",&time_in[x],&min[x]);
p(" Time out for the day of %s: ", day[x]);
s("%d%s",&time_out[x],&min[x]);
twhrs=(time_out[x]-time_in[x]-1)+twhrs;
}
clrscr();
showmsg();
printtime();
g(21,6);p("Enter your Payroll Coverage Date.");
g(18,7);p("Date must be valid and on the date of work. \n");
p("\n Payroll Coverage Date: ");
scanf("%c",date);
gets(date);
{
if(level==1)
srate=350.00;
else if(level==2)
srate=450.00;
else if(level==3)
srate=550.00;
else
srate=750.00;
}
rinc=(srate/8)*twhrs;
clrscr();
showmsg();
printtime();
g(21,5);p(" Program Output and Employee Details ");
g(21,6);p("_____________________________________\n");
p("\n[Company Employee Information]\n");
p(" Employee Name: %s %s %s\n",empna,empmidna,emplastna);
p(" Employee Code: %s\n",empcode);
p(" Salary Level: %d\n\n",level);
p("\n[Employee's Work Rate Information]\n");
p(" Salary Rate: %.02f\n",srate);
p(" Coverage Date: %s\n",date);
p(" Total Hours Worked: %d\n\n",twhrs);
p(" \nREGULAR WORKING INCOME: %.02f\n",rinc);
g(27,23);p("Press a key to terminate...");
}

//MAIN: The Main Program Operations
main()
{
clrscr();
showmsg();
printtime();
empfile=fopen("employee.txt","rt");
dtrfile=fopen("dtr.txt","wt");
g(27,6);p("Search for Employee Code\n");
p("\n Please enter Employee Code: ");
s("%s",&searchempcode);
readfile();
found=0;
while(!feof(empfile)&& found==0)
{
if(strcmp(empcode,searchempcode)==0)
{
clrscr();
showmsg();
printtime();
g(24,6);p("Employee Company Information");
g(27,7);p("[Code found: %s ]\n",empcode);
p("\n Employee Name: %s %s %s\n",empna,empmidna,emplastna);
p(" Employee Code: %s\n",empcode);
p(" Salary Level: %d\n",level);
p("\n\n Press any key to continue...");
getch();
process_data();
writefile();
found=1;
}
else
{
readfile();
clrscr();
showmsg();
printtime();
g(24,12);p("Sorry, we have found no records.");g(26,14);p("Please try again later.");
}
}
fclose(empfile);
fclose(dtrfile);
getch();
}

// end of file.

It displayed my program output very correctly,
I can provide screenshots of my screen output if requested.
The only thing that does my code incorrectly is my file output.

This is the result of writing into a new file (the output).
I attached the Notepad file DTR.TXT:
DTR.TXT

If needed for analyzation, here's my Notepad read file EMPLOYEE.TXT:
employee.txt

Help is really appreciated.
Please accept my "Thank you very much" for those that may help. :)

Attachments
Carlos Sumulat DelaTierro emp-010 1
Raven Ricochetta Romualdez emp-020 2
Amethyst Villalobos Romualez emp-030 3
Raymundo Garrena Baghatsing emp-040 2
Angel YoungHusband Locsin emp-050 1
Michael Mannyiac Murray emp-060 3
Oswaldo Carreon Datungbacak emp-070 2
Pierce Binatogan Brasoman emp-080 1
Reynolds Amarillo Wraff emp-090 2
Sienna Anderson Santamaria emp-100 3
Travis Imam McMacoy emp-004 2
Ujtsselmeer Mariena Jaimenus emp-044 1
Maria Theressee SubUrbano emp-444 4
Administrator Dummy Test admin 5

Wait, guys, I'm confused. Is this appropriate for a C forum although I use C language in my code? Because I'm using a C++ Compiler, my assumption is to post it here in C Forum.
Well it's okay if someone moves this thread in C++ area.
I'm just currently a newbie in such forums.

C++ compilers build C programs. Be confused no longer, grasshopper.

Please explain why you are using the following headers:

#include<dos.h>
#include<iostream.h>

And what is the purpose behind:

#define g gotoxy
#define p printf
#define s scanf
#define fp fprintf
#define fs fscanf

Unless there some reason I don't fathom behind this, all that these defines do is confuse the reader.

Don't be confused...

<dos.h> and <iostream.h> are libraries, part of my C++ and C Compiler.

I used <dos.h> because it is required by my void printtime() subroutine.
(Required for printing the system time in my program.)

The <iostream.h> is used for Input-Output streaming function things.
(Never mind the iostream.h, anyway.
I used it because of my problem that something is wrong in my code, the file output.)


I use #define as substitute for a function.
Example:

#print p printf

I define p as representation of printf function.
To wit:

Line 109:	p("\n Payroll Coverage Date:   ");

Instead of:

Line 109:	printf("\n Payroll Coverage Date:   ");

Both of my compilers recognize that codes.

By the way, I use two compilers, Borland C Compiler 2.0(1987-1988), and Borland C++ Compiler. Whatever my purpose in it is because my school's computers use the first one, while I use the other one in USB Flash Drive (Via DOSBox) because I am also trying to learn C++.

But that's not my problem, anyway.
Still my problem is the file output...

Edited 5 Years Ago by CityThrille: n/a

Don't be confused...

<dos.h> and <iostream.h> are libraries, part of my C++ and C Compiler.

I used <dos.h> because it is required by my void printtime() subroutine.
(Required for printing the system time in my program.)

The <iostream.h> is used for Input-Output streaming function things.
(Never mind the iostream.h, anyway.
I used it because of my problem that something is wrong in my code, the file output.)


I use #define as substitute for a function.
Example:

#print p printf

I define p as representation of printf function.
To wit:

What WaltP said was,

1) <dos.h> : is not a part of the standard C library. It is compiler specific.
2) <iostream.h>: You seem to be using an old compiler. Current C++ standards say this
Notice there is no ".h"

3)

#print p printf

That does work. But it reduces readability of code.


Also, i tried compiling the code on my machine, on VC++. It is quite hard to see where the error is because i would have to edit a lot of stuff in code since it won't be supported here. I removed most functions you had used for formatting(gotoxy). But there were some other parts that had compiler specific code.

Anyhow, i removed those parts and tried debugging. I'm not sure why you used this:

scanf("%c",date);
gets(date);

So, what you could do is, use only standard C functions and rewrite the code. It wouldn't take much time.(Maybe for replacing gotoxy() it would). But it would help everyone to help better.

PS: Kindly use the exact function names instead of macros as WaltP suggested. It becomes hard to read code otherwise.

Edited 5 Years Ago by myk45: n/a

Oh, sorry.

I used the..

scanf("%c",date);
    gets(date);

Because maybe either choosing one of them will not display my
"Payroll Coverage Date" in with spaces, example "December 12, 2012".
So I used both. Although it worked.

I have read a thing that gets() is unsecure because you can type anything beyond the specified array.

I actually used #define in a purpose, to save time in coding.

Okay.
To understand my code for us all,
maybe I will redefine my code for this forum post only.
(although it will take me extra time for recoding)
So that i got the solution from my problem, the file output.

In maybe some several minutes I will post the redefined code. Sigh.

The redefined code:

/*	My Payroll System	*/
/*----------------------------------------------*/
//	Start of file.

//Include Libraries

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<time.h>

//i wonder why it is turned green here in this part.
//<iostream.h> removed as suggested.
//#include<iostream.h>

//Pointer Chars for Time-in and Time-out
char *day[5]={"Monday","Tuesday","Wednesday","Thursday","Friday"};

//Variables with Arrays
int time_in[2];
int time_out[2];
char empna[30];
char empmidna[15];
char emplastna[30];
char empcode[30];
char date[30];
char min[5];
char searchempcode[30];

//Variables
int found, x;
int level;
int twhrs=0;
float rinc;
float srate=0;

//File Operations
FILE *empfile;
FILE *dtrfile;

//SUBROUTINE: Prints the current time (Optional)
void printtime()
{
	struct time t;
	
	gettime(&t);                                 
	{
	gotoxy(60,24);printf("[ %2d:%02d:%02d.%02d ]\n", t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
	}
}

//SUBROUTINE: Header Bar Message (Optional)
void showmsg()
{
	gotoxy(22,2);printf("Spectre Reviewals Examination Company");g(25,3);p("Assessment :  Payroll System");
	gotoxy(1,4);printf("[------------------------------------------------------------------------------]\n");
}

//SUBROUTINE: Read File Operations
void readfile()
{
	fscanf(empfile, "%s", &empna);
	fscanf(empfile, "%s", &empmidna);
	fscanf(empfile, "%s", &emplastna);
	fscanf(empfile, "%s", &empcode);
	fscanf(empfile, "%d", &level);	
}

//SUBROUTINE: Write File Operations
void writefile()
{
	showmsg();
	printtime();
	fprintf(dtrfile, "%s : ", empcode);
	for(x=0;x<5;x++)
	{	
		fprintf(dtrfile, " %d%s ", time_in[x], min[x]);
		fprintf(dtrfile, " %d%s ", time_out[x], min[x]);
	}
}

//SUBROUTINE: File and Program Process Operations
void process_data()
{
	clrscr();
	showmsg();
	printtime();
	gotoxy(13,6);printf("Enter the login and logout time for the days described.");
	gotoxy(19,7);printf("Clock times must be in military format.");
	gotoxy(22,8);printf("(Example: Eight o' clock = 0800) \n");
	for(x=0;x<5;x++)
	{
		printf("\n Time in for the day of %s:   ", day[x]);
		scanf("%d%s",&time_in[x],&min[x]);
		printf(" Time out for the day of %s:   ", day[x]);
		scanf("%d%s",&time_out[x],&min[x]);
		twhrs=(time_out[x]-time_in[x]-1)+twhrs;
	}
	clrscr();
	showmsg();
	printtime();
	gotoxy(21,6);printf("Enter your Payroll Coverage Date.");
	gotoxy(18,7);printf("Date must be valid and on the date of work. \n");
	printf("\n Payroll Coverage Date:   ");
	//---Which part shall I remove here?
	scanf("%c",date);
	gets(date);
	//---
	{
		if(level==1)
			srate=350.00;
		else if(level==2)
			srate=450.00;
		else if(level==3)
			srate=550.00;
		else
			srate=750.00;
	}
	rinc=(srate/8)*twhrs;
	clrscr();
	showmsg();
	printtime();
	gotoxy(21,5);printf(" Program Output and Employee Details ");
	gotoxy(21,6);printf("_____________________________________\n");
	printf("\n[Company Employee Information]\n");
	printf(" Employee Name:          %s %s %s\n",empna,empmidna,emplastna);
	printf(" Employee Code:          %s\n",empcode);
	printf(" Salary Level:           %d\n\n",level);
	printf("\n[Employee's Work Rate Information]\n");
	printf(" Salary Rate:            %.02f\n",srate);
	printf(" Coverage Date:          %s\n",date);
	printf(" Total Hours Worked:     %d\n\n",twhrs);
	printf(" \nREGULAR WORKING INCOME:    %.02f\n",rinc);
	gotoxy(27,23);printf("Press a key to terminate...");
}

//MAIN: The Main Program Operations
main()
{
	clrscr();
	showmsg();
	printtime();
	empfile=fopen("employee.txt","rt");
	dtrfile=fopen("dtr.txt","wt");
	gotoxy(27,6);printf("Search for Employee Code\n");
	printf("\n Please enter Employee Code:   ");
       	scanf("%s",&searchempcode);
	readfile();
	found=0;
	while(!feof(empfile)&& found==0)
	{
		if(strcmp(empcode,searchempcode)==0)
		{
			clrscr();
			showmsg();
			printtime();
			gotoxy(24,6);printf("Employee Company Information");
			gotoxy(27,7);printf("[Code found: %s ]\n",empcode);
			printf("\n Employee Name:    %s %s %s\n",empna,empmidna,emplastna);
			printf(" Employee Code:    %s\n",empcode);
			printf(" Salary Level:     %d\n",level);
			printf("\n\n Press any key to continue...");
			getch();
			process_data();
			writefile();
			found=1;
		}
		else
		{
			readfile();
			clrscr();
			showmsg();
			printtime();
			gotoxy(24,12);printf("Sorry, we have found no records.");gotoxy(26,14);printf("Please try again later.");
		}
	}
	fclose(empfile);
	fclose(dtrfile);
	getch();
}

//	end of file.

Sorry guys, I must follow my old preferences, because my mentors and my Programming classmates
(maybe, if I explained this to them) may be confused in the new C & C++ standard.

That's the reason i still use the old compilers.

Hope that you and I (and to others that have the same problem)
got the solution... Merci. :)

Edited 5 Years Ago by CityThrille: n/a

A small question.

char min[5];

What is that being used for?

for the recording of the time.
My mentor wants me to accept numbers that includes colons
Example: Eight o' clock: 08:00

In here:

char min[5];

and,

scanf("%d%s",&time_in[x],&min[x]);

so that my time_in[x] may accept only 2 characters, the next characters belong to min[x]...

Don't forget to look at the attachments sir. Merci.

Edited 5 Years Ago by CityThrille: n/a

Hmm these were the errors:

for(x=0;x<5;x++)
{	
    fprintf(dtrfile, " %d%s ", time_in[x], min[x]);
    fprintf(dtrfile, " %d%s ", time_out[x], min[x]);
}

AND

for(x=0;x<5;x++)
{
    printf("\n Time in for the day of %s:   ", day[x]);
    scanf("%d%s",&time_in[x],&min[x]);
    printf(" Time out for the day of %s:   ", day[x]); 
    scanf("%d%s",&time_out[x],&min[x]);
    twhrs=(time_out[x]-time_in[x]-1)+twhrs;
}

You were using a one dimensional array of characters. What you needed was an array of pointer to chars or something like this:

char min[10][5]; // 10 ":xx"s can be stored now.

      OR

char *min[10];   // array of 10 char ptrs

What i mean by ":xx"s can be stored now. is:

eg: 09:00 time in
19:30 time out.
Now, min[0] -> :00
min[1] -> :30

So, making these changes would get it to work. Also, you still are using gotoxy() and other non-standard C functions. Are they a requirement in the course?

Hmm these were the errors:

for(x=0;x<5;x++)
{	
    fprintf(dtrfile, " %d%s ", time_in[x], min[x]);
    fprintf(dtrfile, " %d%s ", time_out[x], min[x]);
}

AND

for(x=0;x<5;x++)
{
    printf("\n Time in for the day of %s:   ", day[x]);
    scanf("%d%s",&time_in[x],&min[x]);
    printf(" Time out for the day of %s:   ", day[x]); 
    scanf("%d%s",&time_out[x],&min[x]);
    twhrs=(time_out[x]-time_in[x]-1)+twhrs;
}

You were using a one dimensional array of characters. What you needed was an array of pointer to chars or something like this:

char min[10][5]; // 10 ":xx"s can be stored now.

      OR

char *min[10];   // array of 10 char ptrs

What i mean by ":xx"s can be stored now. is:

eg: 09:00 time in
19:30 time out.
Now, min[0] -> :00
min[1] -> :30

So, making these changes would get it to work. Also, you still are using gotoxy() and other non-standard C functions. Are they a requirement in the course?

Thnak you sir for the information provided.
But I think it will work on my both my Borland compiler. But i will still try it.


As i have stated earlier, yes.
It is required because we are still using an old compiler,
although it opposed some of it in new C standards.
And it's outdated.

I will try your suggestions.
I will post back the result. Merci.

Edited 5 Years Ago by CityThrille: n/a

emp-050 - 8:
&‹G;n®u/ƒ>n®Bt#ƒ>n®Ctƒ>n®htƒ>n®Dt¸®8:
&‹G;n®u/ƒ>n®Bt#ƒ>n®Ctƒ>n®htƒ>n®Dt¸®8:
&‹G;n®u/ƒ>n®Bt#ƒ>n®Ctƒ>n®htƒ>n®Dt¸®8:
&‹G;n®u/ƒ>n®Bt#ƒ>n®Ctƒ>n®htƒ>n®Dt¸®8:
&‹G;n®u/ƒ>n®Bt#ƒ>n®Ctƒ>n®htƒ>n®Dt¸®8:
&‹G;n®u/ƒ>n®Bt#ƒ>n®Ctƒ>n®htƒ>n®Dt¸®8:
&‹G;n®u/ƒ>n®Bt#ƒ>n®Ctƒ>n®htƒ>n®Dt¸®17:
&‹G;n®u/ƒ>n®Bt#ƒ>n®Ctƒ>n®htƒ>n®Dt¸®8:
&‹G;n®u/ƒ>n®Bt#ƒ>n®Ctƒ>n®htƒ>n®Dt¸®17:
&‹G;n®u/ƒ>n®Bt#ƒ>n®Ctƒ>n®htƒ>n®Dt¸®

It displayed the inappropriate written output in DTR.TXT

Can you help me sir with this one?
I was trying to imitate what my mentor showed me
that must be the file output in DTR.TXT:
Times must be in military format.


emp-070 : 08:00,17:00,08:00,17:00,08:00,17:00,08:00,17:08:00,17:00


It must start with the employee code (empcode), the time_in[array] and the time_out[array] which is looped five times a day from Monday to Friday.

Well it works for me. Paste the modified code here.

Here's the code.

/*	My Payroll System	*/
/*----------------------------------------------*/
//	Start of file.

//Include Libraries
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<dos.h>
#include<time.h>
//removed as requested.
//#include<iostream.h>

//Pointer Chars for Time-in and Time-out
char *day[5]={"Monday","Tuesday","Wednesday","Thursday","Friday"};

//Variables with Arrays
int time_in[2];
int time_out[2];
char empna[30];
char empmidna[15];
char emplastna[30];
char empcode[30];
char date[30];
char *min[20];
char searchempcode[30];

//Variables
int found, x;
int level;
int twhrs=0;
float rinc;
float srate=0;

//File Operations
FILE *empfile;
FILE *dtrfile;

//SUBROUTINE: Prints the current time (Optional)
void printtime()
{
	struct time t;
	
	gettime(&t);                                 
	{
	gotoxy(60,24);printf("[ %2d:%02d:%02d.%02d ]\n", t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
	}
}

//SUBROUTINE: Header Bar Message (Optional)
void showmsg()
{
	gotoxy(22,2);printf("Spectre Reviewals Examination Company");g(25,3);p("Assessment :  Payroll System");
	gotoxy(1,4);printf("[------------------------------------------------------------------------------]\n");
}

//SUBROUTINE: Read File Operations
void readfile()
{
	fscanf(empfile, "%s", &empna);
	fscanf(empfile, "%s", &empmidna);
	fscanf(empfile, "%s", &emplastna);
	fscanf(empfile, "%s", &empcode);
	fscanf(empfile, "%d", &level);	
}

//SUBROUTINE: Write File Operations
void writefile()
{
	showmsg();
	printtime();
	fprintf(dtrfile, "%s : ", empcode);
	for(x=0;x<5;x++)
	{	
		fprintf(dtrfile, " %d%s ", time_in[x], min[x]);
		fprintf(dtrfile, " %d%s ", time_out[x], min[x]);
	}
}

//SUBROUTINE: File and Program Process Operations
void process_data()
{
	clrscr();
	showmsg();
	printtime();
	gotoxy(13,6);printf("Enter the login and logout time for the days described.");
	gotoxy(19,7);printf("Clock times must be in military format.");
	gotoxy(22,8);printf("(Example: Eight o' clock = 0800) \n");
	for(x=0;x<5;x++)
	{
		printf("\n Time in for the day of %s:   ", day[x]);
		scanf("%d%s",&time_in[x],&min[x]);
		printf(" Time out for the day of %s:   ", day[x]);
		scanf("%d%s",&time_out[x],&min[x]);
		twhrs=(time_out[x]-time_in[x]-1)+twhrs;
	}
	clrscr();
	showmsg();
	printtime();
	gotoxy(21,6);printf("Enter your Payroll Coverage Date.");
	gotoxy(18,7);printf("Date must be valid and on the date of work. \n");
	printf("\n Payroll Coverage Date:   ");
	//---Which part shall I remove here?
	scanf("%c",date);
	gets(date);
	//---
	{
		if(level==1)
			srate=350.00;
		else if(level==2)
			srate=450.00;
		else if(level==3)
			srate=550.00;
		else
			srate=750.00;
	}
	rinc=(srate/8)*twhrs;
	clrscr();
	showmsg();
	printtime();
	gotoxy(21,5);printf(" Program Output and Employee Details ");
	gotoxy(21,6);printf("_____________________________________\n");
	printf("\n[Company Employee Information]\n");
	printf(" Employee Name:          %s %s %s\n",empna,empmidna,emplastna);
	printf(" Employee Code:          %s\n",empcode);
	printf(" Salary Level:           %d\n\n",level);
	printf("\n[Employee's Work Rate Information]\n");
	printf(" Salary Rate:            %.02f\n",srate);
	printf(" Coverage Date:          %s\n",date);
	printf(" Total Hours Worked:     %d\n\n",twhrs);
	printf(" \nREGULAR WORKING INCOME:    %.02f\n",rinc);
	gotoxy(27,23);printf("Press a key to terminate...");
}

//MAIN: The Main Program Operations
main()
{
	clrscr();
	showmsg();
	printtime();
	empfile=fopen("employee.txt","rt");
	dtrfile=fopen("dtr.txt","wt");
	gotoxy(27,6);printf("Search for Employee Code\n");
	printf("\n Please enter Employee Code:   ");
       	scanf("%s",&searchempcode);
	readfile();
	found=0;
	while(!feof(empfile)&& found==0)
	{
		if(strcmp(empcode,searchempcode)==0)
		{
			clrscr();
			showmsg();
			printtime();
			gotoxy(24,6);printf("Employee Company Information");
			gotoxy(27,7);printf("[Code found: %s ]\n",empcode);
			printf("\n Employee Name:    %s %s %s\n",empna,empmidna,emplastna);
			printf(" Employee Code:    %s\n",empcode);
			printf(" Salary Level:     %d\n",level);
			printf("\n\n Press any key to continue...");
			getch();
			process_data();
			writefile();
			found=1;
		}
		else
		{
			readfile();
			clrscr();
			showmsg();
			printtime();
			gotoxy(24,12);printf("Sorry, we have found no records.");gotoxy(26,14);printf("Please try again later.");
		}
	}
	fclose(empfile);
	fclose(dtrfile);
	getch();
}

//	end of file.

This is my mentor's desired output for DTR.TXT:

emp-070 : 08:00,17:00,08:00,17:00,08:00,17:00,08:00,17:08:00,17:00

I tried it, but the result for DTR.TXT is here: (i compiled and run a second one:)

emp-090 - 8:(null),8:(null),8:(null),8:(null),8:(null),8:(null),8:(null),17:(null),8:(null),17:(null),

All numbers resulted in 0 (zero) returened as (null), instead of the actuan number zero, 0.

Edited 5 Years Ago by CityThrille: Sorry, I edited it. The outp[ut code converts it to smileys.

You don't seem to be allocating memory for the pointers. Anyway, it works fine for me.

These are the modifications:

//SUBROUTINE: File and Program Process Operations
void process_data()
{
	showmsg();

	int num = 0;
	max(13,6);printf("Enter the login and logout time for the days described.");
	max(19,7);printf("Clock times must be in military format.");
	max(22,8);printf("(Example: Eight o' clock = 0800) \n");
	for(x=0;x<5;x++)
	{
		printf("\n Time in for the day of %s:   ", day[x]);
		scanf("%d%s",&time_in[x],min[num]);
		printf(" Time out for the day of %s:   ", day[x]);
		scanf("%d%s",&time_out[x],&min[num+1]);
		twhrs=(time_out[x]-time_in[x]-1)+twhrs;
		num += 2;
	}
... // continues
}

and

//SUBROUTINE: Write File Operations
void writefile()
{
	showmsg();
	int num = 0;

	fprintf(dtrfile, "%s : ", empcode);
	for(x=0;x<5;x++)
	{	
		fprintf(dtrfile, " %d%s ", time_in[x], min[num]);
		fprintf(dtrfile, " %d%s ", time_out[x], min[num + 1]);
		num += 2;
	}
	
}

These are the changes i made. And min is:

char min[10][5]; // This way, you wouldn't need to allocate memory dynamically as with pointers.

You don't seem to be allocating memory for the pointers. Anyway, it works fine for me.

These are the modifications:

//SUBROUTINE: File and Program Process Operations
void process_data()
{
	showmsg();

	int num = 0;
	max(13,6);printf("Enter the login and logout time for the days described.");
	max(19,7);printf("Clock times must be in military format.");
	max(22,8);printf("(Example: Eight o' clock = 0800) \n");
	for(x=0;x<5;x++)
	{
		printf("\n Time in for the day of %s:   ", day[x]);
		scanf("%d%s",&time_in[x],min[num]);
		printf(" Time out for the day of %s:   ", day[x]);
		scanf("%d%s",&time_out[x],&min[num+1]);
		twhrs=(time_out[x]-time_in[x]-1)+twhrs;
		num += 2;
	}
... // continues
}

and

//SUBROUTINE: Write File Operations
void writefile()
{
	showmsg();
	int num = 0;

	fprintf(dtrfile, "%s : ", empcode);
	for(x=0;x<5;x++)
	{	
		fprintf(dtrfile, " %d%s ", time_in[x], min[num]);
		fprintf(dtrfile, " %d%s ", time_out[x], min[num + 1]);
		num += 2;
	}
	
}

These are the changes i made. And min is:

char min[10][5]; // This way, you wouldn't need to allocate memory dynamically as with pointers.

ahhh.. did you created a new pointer with a new char?

because i get the following recently in my code output:

"Divide error

Abnormal program termination"

Is there any reason for this?

By the way, thank you.
I will try the modification sir.
I will post again the result later.

I got this in my DTR.TXT file output content file recently:

emp-090 - 8:assignment

Divide error

Abnormal program termination

`8:assignment

Divide error

Abnormal program termination

`8:assignment

Divide error

Abnormal program termination

`8:assignment

Divide error

Abnormal program termination

`8:assignment

Divide error

Abnormal program termination

`8:assignment

Divide error

Abnormal program termination

`8:assignment

Divide error

Abnormal program termination

`17:assignment

Divide error

Abnormal program termination

`8:assignment

Divide error

Abnormal program termination

`17:assignment

Divide error

Abnormal program termination

`

Now, the result is here, DTR.TXT:

emp-070 - 8::008::008::008::008::008::008::0017::008::0017::00


Very close to my mentor's desired output for DTR.TXT:

emp-070 : 08:00,17:00,08:00,17:00,08:00,17:00,08:00,17:08:00,17:00

The only problem is that the timeout variable only records when it's Friday (the fifth loop in the modified code void writefile() function.)

Is there any way to improve it?

In my previous code, my program, as I have describe recently, has a DTR.TXT file output as:


I tried it, but the result for DTR.TXT is here: (i compiled and run a second one

emp-090 - 8:(null),8:(null),8:(null),8:(null),8:(null),8:(null),8:(null),17:(null),8:(null),17:(null),

Instead of the actual zeroes, null replaces the zeroes (0) in the file.

Edited 5 Years Ago by CityThrille: n/a

This article has been dead for over six months. Start a new discussion instead.