I am scanning the contents of file and then performing some simple operations.

First i want to scan the file for a particular doctor name that works.

I have two records in the file but its not incrementing the counter to check patients which belong to that doctor and add up fees.

case 1:{
                                        
                                        strcpy(doctor1,"Dr.Robert.Williams");
                                         
                                         while(!feof(customer1) && Found==0)
                                         {
                                                
                                              fscanf(customer1,"%s %s %s %s %s %d %d %d %d",det.name,det.regis,det.pname,det.treatment,det.piont,&det.fees,&det.collect,&det.insure,&det.balance);   
           
                                               if(strcmp(doctor1,det.name)==0)
                                                 {
                                                   count++;
                                                   fees = det.fees + fees;
                                                   collected = det.collect + collected;                                                                                                                                
                                                   Found=1;
                                                 }                                            
                                            
                                            printf("\n\t\t  NAME:%s",det.pname);                                            
                                                 
                                           }
                                           printf("\n\t\t  DOCTORS NAME:%s",doctor1); 
                                           printf("\n\t\t  NUMBER OF PATIENTS:%d",count);
                                           printf("\n\t\t  TREATMENT:%s",det.treatment);
                                           printf("\n\t\t  TOTAL FEE CHARGED:$ %d",fees);
                                           printf("\n\t\t  AMOUNT PAID:$ %d",det.collect);
                                           printf("\n\t\t  FEES COLLECTED:$ %d",collected); 
                                        
                                          }
                                          break;

heres what the file looks like.

Dr.Robert.Williams 1 John.Grisam Cleaning 4/07/09 4500 3400 0 -1100
Dr.Robert.Williams 2 John.Whyte Cleaning 4/07/09 4500 3400 0 -1100

while loop is incorrect. You need to read all the records, not just the first one for that doctor. BTW writing short programs to solve a specific problem save you a lot of time.

#include <stdio.h>
#include <string.h>


struct doctor
{
    char name[80];
    char regis[80];
    char pname[80];
    char treatment[80];
    char piont[80];
    int fees;
    int collect;
    int insure;
    int balance;
};

int ReadLine(FILE* customer1, struct doctor* det)
{
    return fscanf(customer1,"%s %s %s %s %s %d %d %d %d",
        det->name,det->regis,det->pname,det->treatment,
        det->piont,&det->fees,&det->collect,&det->insure,&det->balance);   
    
}

int main()
{
   struct doctor det;
   int Found = 0;
   int count = 0;
   int fees = 0;
   int collected = 0;
   
   char doctor1[] = "Dr.Robert.Williams";
    
    FILE* customer = fopen("textFile1.txt", "r");
                                         
    while( ReadLine(customer, &det) > 0)
    {
                                                
        if(strcmp(doctor1,det.name)==0)
        {
            count++;
            fees += det.fees + fees;
            collected += det.collect; 
        }                                            
    }                                            
                                                 
    printf("\n\t\t  DOCTORS NAME:%s",doctor1); 
    printf("\n\t\t  NUMBER OF PATIENTS:%d",count);
    printf("\n\t\t  TREATMENT:%s",det.treatment);
    printf("\n\t\t  TOTAL FEE CHARGED:$ %d",fees);
    printf("\n\t\t  AMOUNT PAID:$ %d",det.collect);
    printf("\n\t\t  FEES COLLECTED:$ %d",collected); 
                                        
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.