结构体应用,打印的时候出现乱码,请高人看看问题处在哪里?
#include<stdio.h>#include<string.h>
#include<stdlib.h>
struct PersonList
{
char name[20];
char tel[20];
char addr[20];
};
//新建信息
struct PersonList * input()
{
struct PersonList * person ;
struct PersonList p[20]={{"zhangsan","123","sa"},{"lisi","341","qw"}};
static int i=0;
person = p;
return person;
}
//打印信息
void display(struct PersonList *p,int n)
{
int i;
printf("%-20s%-20s%-20s\n","姓名","电话","住址");
printf("\n");
for(i=0;i<n;i++)
printf("%-20s%-20s%-20s\n",p[i].name,p[i].tel,p[i].addr);
}
int main(void)
{
struct PersonList *p;
p=input(); //输入信息
display(p,2);//打印信息
system("pause");
return 0;
}