主题:[讨论]求助null pointer assignment修改
程序运行到一半就截止了然后显示null pointer assignment,求助高手修改。明天要交报告了……
通讯薄
#include "string.h"
#include "stdio.h"
#include <math.h>
#define max 200
typedef struct linklist
{
char name[10];
char addr[40];
long PH;
struct linklist *next;
}linklist;
void creat_l(linklist *h) /初始/
{
int c;
h=(linklist *)malloc(sizeof(linklist));
h->next=NULL;
printf("please print name ");
scanf("%s",h->name);
printf("please import address and telephone number.\n");
scanf("%s",h->addr);
scanf("%ld",&c);
h->PH=c;
}
void add(char N[],linklist *h) /添加人/
{int b;
linklist *q,*s;
q=h;
while(q!=NULL)
{
if(strcmp(q->name,N)>=0&&q->next!=NULL)
{
q=q->next;
}
else
{ s=(linklist *)malloc(sizeof(linklist));
strcpy(s->name,N);
printf("please input address and telephone number.\n");
scanf("%s",s->addr);
scanf("%ld",&b);
s->PH=b;
s->next=q->next;
q->next=s;
}
}
}
void dele(linklist *h) /删除人/
{
linklist *q,*s;
char n[20];
printf("name is:");
scanf("%s",n);
s=h;
q=h->next;
while(q==NULL)
{s=q;
q=q->next;
if(strcmp(q->name,n)==0)
break;
}
if(q==NULL)
{printf("no record\n");
return;}
s->next=q->next;
free(q);
}
void find(linklist *h) /按姓名查找/
{char n[20];
linklist *q;
printf("name is:");
scanf("%s",n);
q=h;
while(q!=NULL&&strcmp(q->name,n)!=0)
q=q->next;
if(strcmp(q->name,n)==0)
{
printf("name:%s\n",n);
printf("address:%s\n",q->addr);
printf("telephone number:%ld\n",q->PH);
}
else
printf("there is not the man.\n");
}
main()
{
int a=1;
char ch,n[20];
linklist *h;
while(a<5)
{
printf("*********1. creat book*********\n");
printf("*********2. add *********\n");
pribtf("*********3. find *********\n");
printf("*********4. delete *********\n");
printf("*********5. end *********\n");
printf("please choose number of serve.\n");
scanf("%d",&a);
switch(a)
{
case 1: {
creat_l(h);
}break;
case 2:
{
printf("input name.\n");
scanf("%s",n);
add(n,h);
}break;
case 3:{
find(h);
}break;
case 4:
{dele(h);
}break;
}
}
printf("\n************** Bye ************** ");
}
求助........
通讯薄
#include "string.h"
#include "stdio.h"
#include <math.h>
#define max 200
typedef struct linklist
{
char name[10];
char addr[40];
long PH;
struct linklist *next;
}linklist;
void creat_l(linklist *h) /初始/
{
int c;
h=(linklist *)malloc(sizeof(linklist));
h->next=NULL;
printf("please print name ");
scanf("%s",h->name);
printf("please import address and telephone number.\n");
scanf("%s",h->addr);
scanf("%ld",&c);
h->PH=c;
}
void add(char N[],linklist *h) /添加人/
{int b;
linklist *q,*s;
q=h;
while(q!=NULL)
{
if(strcmp(q->name,N)>=0&&q->next!=NULL)
{
q=q->next;
}
else
{ s=(linklist *)malloc(sizeof(linklist));
strcpy(s->name,N);
printf("please input address and telephone number.\n");
scanf("%s",s->addr);
scanf("%ld",&b);
s->PH=b;
s->next=q->next;
q->next=s;
}
}
}
void dele(linklist *h) /删除人/
{
linklist *q,*s;
char n[20];
printf("name is:");
scanf("%s",n);
s=h;
q=h->next;
while(q==NULL)
{s=q;
q=q->next;
if(strcmp(q->name,n)==0)
break;
}
if(q==NULL)
{printf("no record\n");
return;}
s->next=q->next;
free(q);
}
void find(linklist *h) /按姓名查找/
{char n[20];
linklist *q;
printf("name is:");
scanf("%s",n);
q=h;
while(q!=NULL&&strcmp(q->name,n)!=0)
q=q->next;
if(strcmp(q->name,n)==0)
{
printf("name:%s\n",n);
printf("address:%s\n",q->addr);
printf("telephone number:%ld\n",q->PH);
}
else
printf("there is not the man.\n");
}
main()
{
int a=1;
char ch,n[20];
linklist *h;
while(a<5)
{
printf("*********1. creat book*********\n");
printf("*********2. add *********\n");
pribtf("*********3. find *********\n");
printf("*********4. delete *********\n");
printf("*********5. end *********\n");
printf("please choose number of serve.\n");
scanf("%d",&a);
switch(a)
{
case 1: {
creat_l(h);
}break;
case 2:
{
printf("input name.\n");
scanf("%s",n);
add(n,h);
}break;
case 3:{
find(h);
}break;
case 4:
{dele(h);
}break;
}
}
printf("\n************** Bye ************** ");
}
求助........