|
5鱼币
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
void readdata();
void findemp();
typedef struct Custom
{
char no[9];
char name[10];
char adress[10];
char phone[12];
long int price;
struct Custom *next;
}EMP;
EMP *emp_first,*emp_end;
int main ()
{
readdata();
findemp();
system("PAUSE");
system("cls");
}
void readdata()
{
FILE *fp;
EMP *emp1;
if((fp=fopen("emp.txt","rb+"))==NULL)
{
return;
}
while(!feof(fp))
{
emp1=(EMP *)malloc(sizeof(EMP));
if(emp1=NULL)
{
printf("内存分配失败\n");
getchar();
return;
}
fread(emp1,sizeof(EMP),1,fp);
if(feof(fp))
break;
if(emp_first==NULL)
{
emp_first=emp1;
emp_end=emp1;
}
else
{
emp_end->next=emp1;
emp_end=emp1;
}
emp_end->next=NULL;
}
fclose(fp);
}
void findemp()
{ EMP *findno(char *no);
char str[13];
EMP *emp1;
printf("输入要查询编号:");
scanf("%s",str);
emp1=findno(str);
printf("%d",emp1);
}
EMP *findno(char *no)
{
EMP *emp1;
emp1=emp_first;
while(emp1)
{
if(strcmp(no,emp1->no)==0)
return emp1;
emp1=emp1->next;
}
return NULL;
}
为什么建立的链表里数据一直都是空。返回的值是0.
如果是文件问题,文件里面应该怎么打才正确。
|
最佳答案
查看完整内容
楼主太不小心了吧。if语句里不是“=”符号,而应该是“==”
|