C Program use LARGE STRUCTURE & ARRAY

Vyom

The Power of x480
Staff member
Admin
Congo. Please post a snippet of the solution for others in case they stuck with similar situation.
 
OP
kARTechnology

kARTechnology

Sony " VA" "IO"
Congo. Please post a snippet of the solution for others in case they stuck with similar situation.
well the output thingy not completely completed but heres the full code...its messy...the final salary summary is not yet completed for each employee
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>

void dummy(float *a)
{
    float b=*a; //perform some floating access
    dummy (&b); //calling a floating point function
}

main()

{
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );

struct employee
	{
	int rn;
	char name[30];
	int salary;
	}emp[100];
struct temp
{
	int	hour[40];
	int	min[40];
	int	mins[40];
	int	rec;
	float	totmins;
	int	totsal;
	char	status[30];
	int	temp;
	}t;

int    t1,t2,t3,t4,    y1,m1,d1,  y2,m2,d2,  y,m,d,  i,j,k,l,noofemp,  beginho,beginm,endh,endm,beginmins,endmins;
char fname[20],t5[30],t6,t7;
clrscr();


	



printf("Edit \"empdetails.txt\" for adding new / changing Roll No, Name, Salary/day.   Name: Max 30 Characters");
getch();
d1;d2;m1;   m2;y1;y2;

printf("Enter begining date: MM DD YY:");
if ((scanf("%d%d%d",&d1,&m1,&y1)!=3))
{printf("Invalid input");}

printf("\nEnter ending date: MM DD YY:");
if ((scanf("%d%d%d",&d2,&m2,&y2)!=3))
{printf("Invalid input"); }

if(y1-y2>1)
	{printf("\nCan't input year period > 1 year");getch(); exit(0);}
else if (m1>12||m2>12)
	{printf("\nCant input month > 12");getch(); exit(0);}
else if (d1>31||d2>31)
	{printf("\nCant input day > 31");getch(); exit(0);}

printf("\nEnter Shift Begin Time: HH MM: ");
scanf("%d%d",&beginho,&beginm);
if(beginho>23)
{printf("\nCan't input HH:%d > 23",beginho);getch(); exit(0);}
if(beginm>59)
{printf("\nCan't input MM:%d > 59",beginm);getch(); exit(0);}
printf("\nEnter Shift End Time: HH MM: ");
scanf("%d%d",&endh,&endm);
if(endh>23)
{printf("\nCan't input HH > 23");getch(); exit(0);}
if(endm>59)
{printf("\nCan't input HH > 59");getch(); exit(0);}
beginmins=(beginho*60)+beginm;
endmins=(endh*60)+endm;

	FILE *emp_file;
	FILE *calcsal_file;
	emp_file = fopen("emp.txt","r");
	calcsal_file = fopen("calcsalary.txt","w");

if(emp_file==NULL)
{
	printf("\nERROR Accessing source file for computing salary.\n\nPlease use a text document with the following info:\n Roll	Name	Salary/Day\n\n\n\nFilename of the text document MUST BE \"empdetails\"\ (without the quotes\) ");
	getch();
	exit(0);
}

/*--------- get data from file --------*/
printf("\nReading Employee Details.");
noofemp=0;

while(fscanf(emp_file,"%d%s%d",&t1,&t5,&t3)!=EOF)
{
emp[t1].rn=t1;
strcpy(emp[t1].name,t5);
emp[t1].salary=t3;

if(noofemp<t1)
noofemp=t1;
}

printf("\nTotal Number of Employees: %d",noofemp);
printf("\nEMPLOYEES LIST:");

for(i=1;i<=noofemp;i++)
printf("\nRoll:%d Name:%-30s Salary/Day:%d",emp[i].rn,emp[i].name,emp[i].salary);

fclose(emp_file);






/*--------- get details from fp log file --------*/
fprintf(calcsal_file,"\n     COMPANY NAME  |  Salary Calculator v3.0  |  Report From %d-%d-%d to %d-%d-%d  |  Begin Time:%02d:%02d  End Time:%02d:%02d  |  Run on: %s",d1,m1,y1,d2,m2,y2,beginho,beginm,endh,endm,asctime(timeinfo));

for(i=1;i<noofemp;i++)
{
fprintf(calcsal_file,"\n\n Roll: %d	 Name:%-30s		Salary/Day:%d   Salary/Hour:%.2f",emp[i].rn,emp[i].name,emp[i].salary,(float)emp[i].salary*60/(endmins-beginmins));
fprintf(calcsal_file,"\n -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
fprintf(calcsal_file,"\n Date      | In      Out | In      Out | In      Out | In      Out | In      Out | In      Out | In      Out | In      Out | In      Out | In      Out | Tot Hrs |       Status        | Sal Day | Sal Hour |  ");

for(y=y1;y<=y2;y ++)
{
 for(m=m1;m<=m2;m++)
  {
   for(d=d1;d<=d2;d++)
    {
	fprintf(calcsal_file,"\n %02d-%02d-%02d  |",d,m,y);
	for(k=0;k<=20;k++)
			{
			t.hour[k]=0;
			t.min[k]=0;
			t.mins[k]=0;
			}
			t.rec=0;
			t.totmins=0;
			t.totsal=0;
			strcpy(t.status,"");
			j=0;  l=0;

	sprintf(fname,"%02d-%02d-%02d.dat",d,m,y);

	emp_file=fopen(fname,"r");
	if(emp_file==NULL)
			{
			printf("\nERROR Accessing %s for computing salary",fname);
			getch();
			}
	
	printf("\nDate:%s     Employee:%d   Name:%-30s",fname,emp[i].rn,emp[i].name);
	while(fscanf(emp_file,"%d %d %d %d \n",&t1,&t2,&t3,&t4)!=EOF)
		{
			if(emp[i].rn==t1)
			{
			t.hour[j]=t2;
			t.min[j]=t3;
			t.mins[j]=t4;
			t.rec=j;
			printf("\nRoll:%02d Time:%02d:%01d  Mins:%04d  Record:%02d",emp[i].rn,t.hour[j],t.min[j],t.mins[j],t.rec);
			if(t.rec%2==0)
			t.totmins-=t.mins[j];
			else
			t.totmins+=t.mins[j];
			j++;
			}
		}

	fclose(emp_file);
	if(t.rec==0)
	{strcpy(t.status,"ABSENT");}
	else
	{
	if(t.rec%2==0)  			//checking outputnch
		{
		strcpy(t.status,"NO OUT");
		l=t.rec+1;
		t.hour[l]=endh;
		t.min[l]=endm;
		t.mins[l]=endmins;
		t.totmins+=t.mins[l];
			}
		if (t.mins[0]>beginmins)
		strcat(t.status," LATE");
		if (t.mins[t.rec]<endmins)
		strcat(t.status," EARLY");
	}
	for(k=0;k<20;k++)			//printin in outs
		{
		fprintf(calcsal_file," ");
		fprintf(calcsal_file,"%02d:%02d",t.hour[k],t.min[k]);

		if(k%2==1)
		fprintf(calcsal_file," |");
		}

	fprintf(calcsal_file," %06.03f  |",(t.totmins/60));



	fprintf(calcsal_file," %-20s|",t.status);

}
}
}
}

fclose(calcsal_file);
getch();
}
 

Vyom

The Power of x480
Staff member
Admin
Great to see you have now removed the nested structures and some other complexities.
We could either get this thread closed, and you can recreate another thread in case of further doubts, OR we could leave it open until you resolve your (this) program for good.
 
Top Bottom