0

I am trying to read input form the user and then print them to a file but the compiler is giving me some error about invalid pointer at the fprintf statements

void addrecord(void)
{
     struct  custinfo info;
     
     FILE *customer;
     
     printf("\n\n\t\t\t  PLEASE ENTER THE CUSTOMER INFORMATION BELOW");
     
     printf("\n\n\t\t\t  REGSISRTATION NUMBER");
     scanf("%d",&info.regis);
     
     printf("\n\n\t\t\t  FIRST NAME:");
     scanf("%s",&info.fname);
     
     printf("\n\n\t\t\t  LAST NAME:");
     scanf("%s",&info.lname);
     
     printf("\n\n\t\t\t  TREATMENT:");
     scanf("%s",&info.treatment);
     
     printf("\n\n\t\t\t  ALLERGIES:");
     scanf("%s",&info.allergies); 
     
     printf("\n\n\t\t\t  DATE OF BIRTH (DD-MNT-YR):");
     scanf("%d",&info.dob);
     
     printf("\n\n\t\t\t  DATE OF LAST APPOINTMENT (24):");
     scanf("%d",&info.date);
     
     printf("\n\n\t\t\t  MONTH OF LAST APPOINNENT (07):");
     scanf("%d",&info.month);
     
     printf("\n\n\t\t\t  YEAR OF LAST APPOINTMENT (1990):");
     scanf("%d",&info.year);     
     
     
     customer = fopen("customer.txt","w");
     
     if (customer!=NULL)
            printf("\n\n\t\t\t  FILE WAS OPENED");
     else
         {
            fprintf("Registration Number:%d\n",info.regis);
            fprintf("Customer Name:%s %s\n",info.fname,info.lname);
            fprintf("Treatment:%s\n",info.treatment); 
            fprintf("Allergies:%s\n",info.allergies);
            fprintf("Date of Birth:%s\n",info.dob);
            fprintf("Last appointment date:%d-%d-%d\n",info.date,info.month,info.month)               
         }
         
     fclose(customer);
     
}

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by WaltP
0

fprintf() takes a FILE * as its first argument (which would be in your case the variable customer ).

Then your logic is backwards, in the sense that if the file is opened succesfully, you inform the user about it. But if the opening of the file fails, you'll be trying to write to the file.

And last but certainly not the least, please use code tags when you post code.

Edited by mitrmkar: o not ö

0

Don't bother.

6 posts with no code tags = 1 warning and 5 infractions.
Fastest ban I've ever seen that wasn't for spam.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.