这是我在这里的第一个问题,我还在学习 c,我正在编写此代码以输入用户银行帐户的详细信息以归档并从文件中读取所有记录,当错误时,错误:invalid type argument of unary '* " (have 'int') 出现在所有指向 struct *ptr 的指针指向整数值的行上(例如第 40 行)
struct usr_act
{
char username[24], address[24], status;
int id, prebal, cp, newbal, pdate;
}a[3];
int j=0;
struct usr_act *ptr;
bool r;
void input()
{
FILE *fp;
fp = fopen("accounts.txt","a+");
if(fp==NULL)
{
printf("Error!!");
exit(1);
}
printf("\n\tRecord %d\n\n",j+1);
fprintf(fp,"Record",j+1);
printf("\nName:- ");
for(int i=0;i<24;i++)
{
scanf("%c",ptr->username[i]);
}
fprintf(fp,"Name:- %s",*(ptr->username));
printf("\nAddress:- ");
for(int i=0;i<24;i++)
{
scanf("%c",ptr->address[i]);
}
fprintf(fp,"Address:- %s",*(ptr->address));
printf("\nCustomer Id:- ");
scanf("%d",ptr->id);
fprintf(fp,"Customer Id:- %d",*(ptr->id)); //Error
printf("\nPrevious balance:- ");
scanf("%d",ptr->prebal);
fprintf(fp,"Previous Balance:- %d",*(ptr->prebal)); //Error
printf("\nCurrent Payment:- ");
scanf("%d",ptr->cp);
fprintf(fp,"Current Payment:- %d",*(ptr->cp)); //Error
printf("\nPayment Date:- ");
scanf("%d",ptr->pdate);
fprintf(fp,"Payment Date:- %d",*(ptr->pdate)); //Error
fclose(fp);
r=true;
}
void calc()
{
FILE *fp;
fp = fopen("accounts.txt","a+");
if(fp==NULL)
{
printf("Error!!");
exit(1);
}
float k;
k = 0.10 * (*(ptr->prebal));
if(*(ptr->cp)>0 && *(ptr->cp)<k)
{
ptr->status='o';
}
else
{
ptr->status='c';
}
fprintf(fp,"Account status:- %c",*(ptr->status));
ptr->newbal= *(ptr->prebal) - (*(ptr->cp));
fprintf(fp,"New Balance:- %d",*(ptr->cp));
fclose(fp);
}
在这之间我有一个显示功能,它显示文件中的数据,这是主要功能
int main()
{
int l;
do
{
ptr=&a[j];
r=false;
printf("\n\tMenu\nk=1, Input details \nk=2, Show patient records \nk=3, Exit \n\nEnter your choice:- ");
scanf("%d",&l);
switch(l)
{
case 1:
{
input();
calc();
break;
}
case 2:
{
display();
break;
}
}
if(r==true)
{
j=j+1;
}
} while(l!=3);
return 0;
}
我该如何解决这个问题?