为什么最后输出的总是乱码.
学习中,写一个出来,输出时最后总是乱码.如下图.大家帮忙看看哪里有问问题.程序代码:
#include<stdio.h> #include<string.h> #define PH struct phone_book FILE *fp; static struct phone_book { char name[20],mail[30],add[50]; int num[15],num1[15],num2[15]; struct phone_book *next; }; PH *put() { PH *p1,*p2,*p; int i=0; printf("key \"q\" to exit\n"); while(getch()!='q') { p2=(PH *)malloc(sizeof(PH)); printf("input name,mail,add,num:\n"); scanf("%s%s%s",p2->name,p2->mail,p2->add); scanf("%s%s%s%%s%s%s",p2->num,p2->num1,p1->num2); if(i==0) { p1=p=p2;p->next=0; } else { p1->next=p2; p2->next=0; p1=p2; } i++; } return p; } main() { PH *p; p=put(); if((fp=fopen("e:\\phone_book.txt","at+"))==NULL) { printf("open the files error,press any key exit!\n"); getch();exit(1); } while(p!=0) { fprintf(fp,"姓名\t\t\t 邮箱\t\t\t\t地址\n"); fprintf(fp,"%s\t%s\t%s\n",p->name,p->mail,p->add); fprintf(fp,"电话\t\t电话1\t\t电话2\n"); fprintf(fp,"%s\t%s\t%s\n\n",p->num,p->num1,p->num2); p=p->next; } fclose(fp); getch(); }