rajsujayks
CSE Freak!
I want to get the input and output as in the files attached.
This is my code:
That is, if I give the command
(assuming the file empin.txt is in C: drive and the code is compiled and saved in the name emp.exe in C: drive), the attached file should be produced...
Please check and tell me what I'm doing wrong. Thanks in advance.
This is my code:
Code:
//Employee Details...
//Execution syntax : "ProgramName InputFile OutputFile"
//Input File should contain grade and name of employee
//separated by a tab with one record per line..
#include <stdio.h>
#include <string.h>
int main(int argc,char *argv[])
{
FILE *in,*out;
char *name,*designation;
float basic,hra,da,gross;
char grade;
//Opening files..
in=fopen(argv[1],"r");
out=fopen(argv[2],"w");
if((in==NULL)||(out==NULL))
{
printf("\n\nEither one or both the specified files cannot be opened!");
return 0;
}
while(feof(in)==0)
{
basic=10000;
fscanf(in,"%c%s",&grade,name);
switch(grade)
{
case 'E':
strcpy(designation,"Engineer");
hra=0.15;
da=0.10;
break;
case 'S':
strcpy(designation,"Supervisor");
hra=0.20;
da=0.10;
break;
case 'P':
strcpy(designation,"Project Head");
hra=0.25;
da=0.15;
break;
case 'H':
strcpy(designation,"Helper");
hra=0.10;
da=0.05;
break;
default:
strcpy(designation,"Unknown");
hra=0;
da=0;
}
gross=basic+(basic*hra)+(basic*da);
fprintf(out,"%s\t%s\t%f",name,designation,gross);
}
fclose(in);
fclose(out);
printf("\n\n\tFile %s generated!",argv[2]);
return 0;
}
That is, if I give the command
Code:
C:\>emp empin.txt empout.txt
Please check and tell me what I'm doing wrong. Thanks in advance.