:为什么我的添加结果是乱码啊

oid xxtj(int d)//添加
{
S head;
head=(S
)malloc(sizeof(S));
head->next=NULL;
FILEfp;
char str[50];
if((fp=fopen("jk0326.txt","a"))==NULL)
{
printf("对不起,文件打开错误!");
return;
}
fgets(str,50,fp);
S
last,q;
last=head;
int i;
for(i=0;i<d;i++)
{
q=(S*)malloc(sizeof(S));
fscanf(fp,"%d %s %s %s %s %d %f",&q->num,q->classify,q->bookname,q->author,q->publish,&q->quantity,&q->price);
q->next=NULL;
last->next=q;
last=q;
}
fclose(fp);
S
p,p1;
int j;
p=head;
printf("请输入要添加的位置的编号: ");
scanf("%d",&j);
while(p->next!=NULL&&(p->num!=j-1))
{
p=p->next;
}
if(p!=NULL)
{
p1=(S
)malloc(sizeof(S));
printf("\n添加数据\n");
printf("\n请输入编号:");
scanf("%d",&p1->num);
printf("\n请输入分类:");
scanf("%s",&p1->classify);
printf("\n请输入书名:");
scanf("%s",p1->bookname);
printf("\n请输入作者:");
scanf("%s",p1->author);
printf("\n请输入出版社:");
scanf("%s",p1->publish);
printf("\n请输入数量:");
scanf("%d",&p1->quantity);
printf("\n请输入单价:");
scanf("%f",&p1->price);
p1->next=p->next;
p->next=p1;
printf("图书相关信息添加成功!");
}
else
printf("\n输入错误,添加失败!");
if((fp=fopen("jk0326.txt","a"))==NULL)
{
printf("对不起,文件打开错误!");
exit(0);
}
p=head->next;
while(p!=NULL)
{
fprintf(fp,"%d %s %s %s %s %d %f",q->num,q->classify,q->bookname,q->author,q->publish,q->quantity,q->price);
p=p->next;
}
fclose(fp);
printf("\n编号 分类 书名 作者 出版社 数量 单价\n");
p=head->next;
while(p!=NULL)
{
printf("%d %-15s %-20s %-20s %-20s %-5d %-12.f\n",p->num,p->classify,p->bookname,p->author,p->publish,p->quantity,p->price);
p=p->next;
}
}

你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。


因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。