hi i would like to ask whether anyone knows how to create an if statement to read a word and then set a count for every time the word appears. it works perfectly fine with integers but it won't read the word that i want it to.
CODE
#include <stdio.h>
#include <conio.h>
char name[20];
int empno;
char dept;
float gpay;
float npay;
float tax;
float ni;
float pension;
float taxtotal;
float hours;
float rate;
int admin;
int sales;
int accounts;
int emps;
float gpays, npays, taxes, nis, pensions;
FILE *empsPtr;
void main()
{
clrscr();
if((empsPtr=fopen("e:employee.dat","r"))==NULL) {
printf("File is empty\n");
}
else{
textcolor(BLUE);
cprintf("\t\tABC Company Employee Report");
printf("\n");
printf("\n");
cprintf("%-10s%15s%8s%12s%6s%10s%10s%8s\n","Name","Employee No.","Depart","Gross Pay","Tax","Health","Pension","Net Pay");
printf("-------------------------------------------------------------------------------\n");
fscanf(empsPtr,"%s%d%s%f%f",name,&empno,dept,&hours,&rate);
while(!feof(empsPtr)){
gpay=hours*rate;
tax=gpay*0.155;
ni=gpay*0.03;
pension=gpay*0.02;
taxtotal=tax+ni+pension;
npay=gpay-taxtotal;
gpays+=gpay;
npays+=npay;
taxes+=tax;
nis+=ni;
pensions+=pension;
printf("%-13s\t%d\t%8s\t%5.2f\t%3.2f\t%3.2f\t%3.2f\t%5.2f\n",name,empno,dept,gpay,tax,ni,pension,npay);
fscanf(empsPtr,"%s%d%s%f%f",name,&empno,dept,&hours,&rate);
}
if(dept=="Accounts") //important stuff apparently starts here
{ accounts++;
}
else if(dept=="Sales")
{ sales++;
}
else { admin++;
}//important stuff apparently ends here
textcolor(RED);
printf("\n");
printf("--------------------------------------------------------------------------------\n");
printf("\t\t\t\t\t%5.2f\t%4.2f\t%4.2f\t%4.2f\t%5.2f\n",gpays, taxes, nis, pensions, npays);
printf("\n");
printf("Total number from Admin Department: %d\n",admin);
printf("Total number from Sales Department: %d\n",sales);
printf("Total number from Accounts Department: %d\n",accounts);
printf("\n");
printf("Total number of employees: %d\n",sales+accounts+admin);
}
fclose(empsPtr);
}
*mod edit - added code tags and removed a few other random bbcode tags