|
发表于 2004-1-14 18:43:49
|
显示全部楼层
#include
struct goods
{
char goods_name[20];
int goods_number;
char goods_sign[20];
float input_price;
float output_price;
struct goods *next;
};
struct goods creat()
{
FILE* fp1;
struct goods *p_head,*p_temp;
p_head=NULL;
if((fp1==fopen("data.txt","r"))==NULL)
{
cout<<"open data.txt failed"<<endl;
fclose(fp1);
return(p_head);
}
int num,i;
num=i=0;
do{
p_temp=(struct goods*)malloc(sizeof(struct goods));
num=fread(p_temp,sizeof(struct goods),1,fp1);
if(num<0)
{
cout<<"read data.txt failed"<<endl;
fclose(fp1);
// exit(1);
return(p_head);
}
if(i==0)
{
p_head->next=p;
i++;
continue;
}
p_temp->next=p_head->next;
p_head->next=p_temp;
}while(num!=0);
fclose(fp1);
return(p_head);
}
//in fact ,if you write code by c++,you should full use these features of c++ |
|