关于C语言的结构指针

来源:百度知道 编辑:UC知道 时间:2024/08/25 02:05:43
我写了一个按照生日来排列朋友目录的程序,但貌似是用指针的时候,在VOID RANKING那个函数那里出了点问题,得不到结果,哪位大大帮忙看一下~
#include<stdio.h>
#include<string.h>
struct frineds_list{
char name[20],telephone[13],address[40],birthday[10];
};
void read(struct frineds_list *,int);
void ranking(struct frineds_list *,int);
void swap(char *,char *);
void main()
{
int n;
struct frineds_list friends[50],*p;
p=friends;
printf("how many friends:");
scanf("%d",&n);
read(p,n);
ranking(p,n);
}
void read(struct frineds_list *p,int n)
{
int i;
for(i=0;i<n;i++,p++){
printf("enter friend's name:");
gets(p->name);
getchar();
printf("enter friend's telephone:");
gets(p->telephone);
getchar();
printf("enter friend's address:");
gets(p->address);
getchar();
printf("enter friend'

#include<stdio.h>
#include<string.h>
#include<malloc.h>
struct frineds_list{
char name[20],telephone[13],address[40],birthday[10];
};
void read(struct frineds_list *,int);
void ranking(struct frineds_list *,int);
void swap(struct frineds_list *px,struct frineds_list *py);
void main()
{
int n;
struct frineds_list friends[50],*p;
p=friends;
printf("how many friends:");
scanf("%d",&n);
read(p,n);
ranking(p,n);
}
void read(struct frineds_list *p,int n)
{
int i;
for(i=0;i<n;i++){
printf("enter friend's name:");
scanf("%s",(p+i)->name);
//getchar();
printf("enter friend's telephone:");
scanf("%s",(p+i)->telephone);
//getchar();
printf("enter friend's address:");
scanf("%s",(p+i)->address);