#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<time.h>
struct supplier{//供货商信息结构体 supplier.txt
char name[20];
char address[50];//地址
char phone[12];//电话
};
typedef struct supplier SUP;//简化,将"结构体类型"重新定义为SUP
struct link_supplier{
char name[20];
char address[50];//地址
char phone[12];//电话
struct link_supplier *next;
};
typedef struct link_supplier LSUP;
int main()//入库记录中的操作员暂且不赋值
{
FILE *fp;
fp=fopen("supplier.txt","wb+");
SUP *psup;
psup=(SUP*)malloc(sizeof(SUP));
strcpy(psup->name,"a");
fwrite(psup,sizeof(SUP),1,fp);
strcpy(psup->name,"b");
fwrite(psup,sizeof(SUP),1,fp);
strcpy(psup->name,"c");
fwrite(psup,sizeof(SUP),1,fp);
fclose(fp);
LSUP *hplsup,*plsup0,*plsup;//哨兵节点
hplsup=plsup0=(LSUP*)malloc(sizeof(LSUP));
hplsup->next=NULL;
fp=fopen("supplier.txt","rb+");
rewind(fp);
psup=(SUP*)malloc(sizeof(SUP));
while(fread(psup,sizeof(SUP),1,fp)!=0){//生成供货商信息链表
plsup0->next=plsup=(LSUP*)malloc(sizeof(LSUP));
plsup->next=NULL;
printf("生成链表过程中plsup->next!=NULL条件为%d\n",plsup->next!=NULL);
strcpy(plsup->name,psup->name);
strcpy(plsup->address,psup->address);
strcpy(plsup->phone,psup->phone);
plsup0=plsup;
}
fclose(fp);
char name[20];
printf("输入供货商名称\n");
scanf("%s",name);
plsup=hplsup;
int flag=0;
while(plsup->next!=NULL&&flag==0){//死循环
plsup=plsup->next;
printf("链表遍历中plsup->next!=NULL条件为%d\n",plsup->next!=NULL);
if(strcmp(plsup->name,name)==0){
flag=1;
}
}
return 55555555;
}
当输入的供货商名称不是a ,不是b ,不是c时,为什么会死循环?