I am trying to try search a file for a record based on on a number is enter which is printed to a file under registratation number.I just want to know if my coding is correct.Below is a sample of the module.

{
     
   
   struct custinfo info;
   
   FILE *customer;  
   
   char number[5];
   int x;
   
   
   printf("\n\n\t  PLEASE ENTER A THE REGISTRATION NUMBER TO BE FOUND:");
   scanf("%s",&number);    


   customer = fopen("customer.txt","r");
    
    do
    {
     
            if (info.regis!=number)
            {                      
           
              fscanf(customer,"%s\n",info.regis);
              fscanf(customer,"%s %s\n",info.fname,info.lname);
              fscanf(customer,"%s\n",info.treatment); 
              fscanf(customer,"%s\n",info.allergies);
              fscanf(customer,"%s %s %s\n",info.date1,info.month1,info.year1);
              fscanf(customer,"%s %s %s\n",info.date,info.month,info.month);               
               }
             else
             {
                printf("\n\n\t\t\t  THE RECORD HAS BEEN FOUND");              
                      
                printf("\n\n\t\t\t  REGISTRATION: %s",info.regis);
                printf("\n\n\t\t\t  CUUSTOMER NAME: %s %s",info.fname,info.lname);
                printf("\n\n\t\t\t  TREATMENT: %s",info.treatment);
                printf("\n\n\t\t\t  ALLERGIES: %s",info.allergies);
                printf("\n\n\t\t\t  DATE OF BIRTH: %s / %s / %s",info.date1,info.month1,info.year1);
                printf("\n\n\t\t\t  DATE OF LAST APPOINTMENT: %s / %s / %s",info.date,info.date,info.year); 
                break;              
                }   
                
      }while(number!=info.regis);            
                       
     fclose(customer);
     
}

When you enter the loop, what is the value of info.regis?

> what is the value of info.regis?

That really doesn't matter, because the comparison at line 21 is guaranteed to yield true.

What kind of error are you getting ?

> what is the value of info.regis?

That really doesn't matter, because the comparison at line 21 is guaranteed to yield true.

True -- but do you know why? And if you do, why don't you correct the OP rather than imply my post is of no help.

True -- but do you know why? And if you do, why don't you correct the OP rather than imply my post is of no help.

Didn't mean to imply that.
Speaking of why, of course I do. I wanted OP to figure this "why" out.
To add a hint, the comparison in question compares not values, but statically allocated pointers, which may not possibly be equal.

What kind of error are you getting ?

I am not really getting an error its just printing nothing

I am not really getting an error its just printing nothing

This > while(number!=info.regis); and this > if (info.regis!=number) would work if they were int or float type, but it does not work as intended if they are array of chars.

For that you can use strcmp() while ( strcmp(number, info.regis) != 0 ) By the way, scanf("%s",&number); number is already the address of the first character. The & is not welcome there. Furthermore, what prevents input of more than five chars which is the maximum capacity of number[5]?

And since we are here customer = fopen("customer.txt","r"); must be checked for success before using the file.

Stop flooding the forums with new threads on this program. Use THIS thread only for your project.

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.