Hi All,
 
I have a question in File management with Structures (arrayed) using C, am 
writing a program and had stucked at a point i.e How to append data at the end 
of Line in a file.
 
It is just like option 1 will take the inputs of employee number, ename, basic 
this info stored in a .txt file. When option 2 is selected just scanf for 
employee number then it should calculate the DA, HRA, TOT SAl and append in the 
concern line of matchig data. 
 
1. While writing the program if the basic declared as Float it is delevering a 
msg "Floating points are linked"
 
2. Unable to scanf the new line character, i.e skiping to next line after the 
logic ends.
 
Eno     Ename   Basic         Da              Hra          TOTSAL
 
1111    Robert   2000.00      
 
2222    Bob       3000.00      250            300            2550.00
 
(1111 Data should be appended in the line ). Please help me in the logic.


      
  ----------

#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<string.h>
#include<graphics.h>
#include<dos.h>
struct emp
{
     long int empno;
     long basic,hra,da,tsal,gsal,pf;
     char name[20],des[10];
};
void banner();
void tims();
struct time t;
void main()
{
        FILE *fp;
        int gd=DETECT,gm;
        int i,j,nvalue,flag=0,nwd=0;
        long k,calsal=0,perday=0;
        char temp[50],ch='~';
        struct emp ep[4];
        initgraph(&gd,&gm,"");
        cleardevice();
        yy:
        setbkcolor(1);
        banner();
        tims();
        gotoxy(15,10);
        printf(" Enter ur option 1. Admission Entry");
        gotoxy(15,11);
        printf("                 2. Pay Slip Generate");
        gotoxy(15,12);
        printf("                 3. View Details");
        gotoxy(15,13);
        printf("                 4. EXIT              = ");
        scanf("%d",&j);
        if(j==1)
        {
           fp=fopen("btechproject.txt","a");
           cleardevice();
           banner();
           tims();
           gotoxy(15,5);
           printf("Your are in Master Entry Form");
           tims();
           gotoxy(15,7);
           printf("Enter Number of New Employee Entries ");
           scanf("%d",&nvalue);
           for(i=1;i<=nvalue;i++)
           {
                cleardevice();
                tims();
                banner();
                gotoxy(10,5);
                printf("Enter Employee Number     : ");
                scanf("%ld",&ep[i].empno);
                tims();
                gotoxy(10,7);
                printf("Enter Employee Name        :");
                scanf("%s",&ep[i].name);
                tims();
                gotoxy(10,9);
                printf("Enter Employee Desig       :");
                scanf("%s",&ep[i].des);
                tims();
                gotoxy(10,11);
                printf("Enter Basic salary         :");
                scanf("%ld",&ep[i].basic);
                
fprintf(fp,"\n%c\t%ld\t%s\t%s\t%ld",ch,ep[i].empno,ep[i].name,ep[i].des,ep[i].basic);
           }
           fclose(fp);
        }
        if(j==2)
        {
             fp=fopen("btechproject.txt","r");
             cleardevice();
             tims();
             setbkcolor(1);
             banner();
             gotoxy(16,5);
             printf("Generation of Pay slip");
             gotoxy(16,7);
             k=0; nwd=0;calsal=0;perday=0;
             printf("Enter Employee Number     : ");
             scanf("%ld",&k);
             printf("\n k value is %d",k);
             flag=0;
             rewind(fp);
             while(!feof(fp))
             {
               tims();
               
fscanf(fp,"%c%ld%s%s%ld%",&ch,&ep[i].empno,&ep[i].name,&ep[i].des,&ep[i].basic);
            //   gotoxy(10,12);
            //   printf("emp number is %ld",ep[i].empno);
               if(ep[i].empno==k)
               {
                        cleardevice();
                        banner();
                        tims();
                        gotoxy(10,6);
                        printf("Enter No. Of Working Days ");
                        scanf("%d",&nwd);
                        perday=ep[i].basic/30;
                        calsal=nwd*perday;
                        ep[i].hra=(calsal*40)/100;
                        ep[i].da=(calsal*18)/100;
                        ep[i].pf=(calsal*12)/100;
                        ep[i].tsal=calsal+ep[i].da+ep[i].hra;
                        ep[i].gsal=ep[i].tsal-ep[i].pf;
                        tims();
                        gotoxy(10,8);
                        printf("Employee Number is      : %ld.00",ep[i].empno);
                        gotoxy(10,10);
                        printf("Employee Name is        : %s",ep[i].name);
                        gotoxy(10,12);
                        printf("Employee Designatio     : %s",ep[i].des);
                        gotoxy(10,13);
                        printf("Employee Basic salary   : %ld.00",ep[i].basic);
                        gotoxy(10,14);
                        printf("Employee House Rent Allw: %ld.00",ep[i].hra);
                        gotoxy(10,15);
                        printf("Employee Dearness Allw  : %ld.00",ep[i].da);
                        gotoxy(10,16);
                        printf("Employee Total Salary   : %ld.00",ep[i].tsal);
                        gotoxy(10,17);
                        printf("Employee Provident Fund : %ld.00",ep[i].pf);
                        tims();
                        gotoxy(10,18);
                        printf("Employee Grand Salary   : %ld.00",ep[i].gsal);
                        fclose(fp);
                        fp=fopen("btechproject.txt","a");
                        
fprintf(fp,"\t%ld\t%ld\t%ld\t%ld\t%ld",ep[i].hra,ep[i].da,ep[i].tsal,ep[i].pf,ep[i].gsal);
                        //             no  na  de   ba   hr  da  tsal  pf  gsal
                        fclose(fp);
                        fp=fopen("btechproject.txt","r");
                        printf("\n\n");
                        flag=1;
                        goto xx;
               }
               i++;
               ep[i].empno=0;

             }
             if(flag==0)
             {
                tims();
                gotoxy(15,13);
                printf("Please Enter correct Employee Number");
                getch();
                cleardevice();
                banner();
                goto yy;
             }
             fclose(fp);
         }
         if(j==3)
         {
             fp=fopen("btechproject.txt","r");
             cleardevice();
             tims();
             gotoxy(15,5);
             setbkcolor(1);
             banner();
             printf("View Details");
             gotoxy(16,8);
             printf("Enter Employee Number     : ");
             scanf("%ld",&k);
             flag=0;
             
while((fscanf(fp,"%c%ld%s%s%ld%ld%ld%ld%ld%ld",&ch,&ep[i].empno,&ep[i].name,&ep[i].des,&ep[i].basic,&ep[i].hra,&ep[i].da,&ep[i].pf,&ep[i].tsal,&ep[i].gsal))!=EOF)
             {
               if(ep[i].empno==k)
               {
                        cleardevice();
                        banner();
                        tims();
                        gotoxy(10,7);
                        printf("Employee Number is      : %ld",ep[i].empno);
                        gotoxy(10,8);
                        printf("Employee Name is        : %s",ep[i].name);
                        gotoxy(10,9);
                        printf("Employee Designatio     : %s",ep[i].des);
                        gotoxy(10,10);
                        printf("Employee Basic salary   : %ld",ep[i].basic);
                        gotoxy(10,11);
                        printf("Employee House Rent Allw: %ld",ep[i].hra);
                        gotoxy(10,12);
                        printf("Employee Dearness Allw  : %ld",ep[i].da);
                        gotoxy(10,13);
                        printf("Employee Total Salary   : %ld",ep[i].tsal);
                        gotoxy(10,14);
                        printf("Employee Provident Fund : %ld",ep[i].pf);
                        gotoxy(10,15);
                        printf("Employee Grand Salary   : %ld",ep[i].gsal);
                        if(ep[i].gsal==0)
                        { gotoxy(25,17);
                          printf("Pay slip not generated");
                        }
                        printf("\n\n");
                        flag=1;
                        goto xx;
               } i++;
               
ep[i].basic=0;ep[i].hra=0;ep[i].da=0;ep[i].pf=0;ep[i].tsal=0;ep[i].gsal=0;
             }
             if(flag==0)
             {
                gotoxy(15,13);
                printf("Please Enter correct Employee Number");
                getch();
                cleardevice();
                banner();
                goto yy;
             }
             fclose(fp);
            }
         /*   if(j>=4)
            {
               cleardevice();
               banner();
               gotoxy(15,13);
               printf("Enter Correct Option ");
               getch();
               goto yy;
             }*/
             if(j==4)
               goto xx;
             xx:
             fclose(fp);
         getch();
}
void banner()
{
        settextstyle(SIMPLEX_FONT,HORIZ_DIR,2);
        textcolor(4);
        outtextxy(145,20,"C LANGUAGE EMPLOYEE DATA PROJECT");
        rectangle(15,10,630,470);
        setbkcolor(1);
}
void tims()
{
       gotoxy(69,4);
       textcolor(3);
       gettime(&t);
       printf("%d:%d:%d",t.ti_hour,t.ti_min,t.ti_sec);
}

[Non-text portions of this message have been removed]

Reply via email to