📄 press.c
字号:
}
printf("the %d name_id has %d lib_num\n",cursor_name,temp.lib_num);
//查询有书则购买
if (temp.lib_num>0)
{
a_book=scrimber_press(press_id, store_id,cursor_name, press_store[1].scrimbe_num[i],a_book);
}
else
{
if (work!=NULL)
{
fprintf(work,"%c did not scrimbe book in press %c\n",store_id,press_id);
fclose(work);
}
return NULL;
}
break;
}
case 'E':
{
for (i=0;i<7;i++)
{
if (strcmp(temp.kind,press_store[2].kind[i])==0)
{
break;
}
}
if (i==7)
{
printf("error in C!\n");
return NULL;
}
printf("the %d name_id has %d lib_num\n",cursor_name,temp.lib_num);
//查询有书则购买
if (temp.lib_num>0)
{
a_book=scrimber_press(press_id, store_id,cursor_name, press_store[2].scrimbe_num[i],a_book);
}
else
{
if (work!=NULL)
{
fprintf(work,"%c did not scrimbe book in press %c\n",store_id,press_id);
fclose(work);
}
return NULL;
}
break;
}
default :
{
printf("store_id error:no this book store!");
}
}//emd switch
fclose(fp);
return a_book;
}//end if
else if (press_id=='B')
{
fp=fopen("book_b","ab+");
if (fp==NULL)
{
printf("%c store cannot open book_a.txt in function search_press\n",store_id);
pthread_exit(NULL);
}
fseek(fp,position,0);
fread(&temp,sizeof(struct book),1,fp);
switch (store_id)
{
case 'C':
{
for (i=0;i<3;i++)
{
if (strcmp(temp.kind,press_store[0].kind[i])==0)
{
break;
}
}
if (i==3)
{
printf("error in C!\n");
return NULL;
}
printf("the %d name_id has %d lib_num\n",cursor_name,temp.lib_num);
//查询有书则购买
if (temp.lib_num>0)
{
a_book=scrimber_press(press_id, store_id,cursor_name, press_store[0].scrimbe_num[i],a_book);
}
else
{
if (work!=NULL)
{
fprintf(work,"%c did not scrimbe book in press %c\n",store_id,press_id);
fclose(work);
}
return NULL;
}
break;
}
case 'D':
{
for (i=0;i<4;i++)
{
if (strcmp(temp.kind,press_store[1].kind[i])==0)
{
break;
}
}
if (i==4)
{
printf("error in D!\n");
return NULL;
}
printf("the %d name_id has %d lib_num\n",cursor_name,temp.lib_num);
//查询有书则购买
if (temp.lib_num>0)
{
a_book=scrimber_press(press_id, store_id,cursor_name, press_store[1].scrimbe_num[i],a_book);
}
else
{
if (work!=NULL)
{
fprintf(work,"%c did not scrimbe book in press %c\n",store_id,press_id);
fclose(work);
}
return NULL;
}
break;
}
case 'E':
{
for (i=0;i<7;i++)
{
if (strcmp(temp.kind,press_store[2].kind[i])==0)
{
break;
}
}
if (i==7)
{
printf("error in C!\n");
return NULL;
}
printf("the %d name_id has %d lib_num\n",cursor_name,temp.lib_num);
//查询有书则购买
if (temp.lib_num>0)
{
a_book=scrimber_press(press_id, store_id,cursor_name, press_store[2].scrimbe_num[i],a_book);
}
else
{
if (work!=NULL)
{
fprintf(work,"%c did not scrimbe book in press %c\n",store_id,press_id);
fclose(work);
}
return NULL;
}
break;
}
default :
{
printf("store_id error:no this book store!");
}
}//end switch
fclose(fp);
return a_book;
}//end else if
}
//出版社留给书店的订购接口用于书店的被动订购
struct book * scrimber_press(char press_id, char store_id,int cursor_name,int num,struct book *a_book)
{
long position=cursor_name * sizeof(struct book);
struct book temp;
int i=0;
FILE *fp;
FILE *work;
work=fopen("work.txt","a+");
if (work==NULL)
{
printf("cannot open work.txt in function scrimber_press\n");
}
if (press_id=='A')
{
fp=fopen("book_a","ab+");
if (fp==NULL)
{
printf("%c store cannot open book_a.txt in function scrimber_press\n",store_id);
pthread_exit(NULL);
}
fseek(fp,position,0);
fread(&temp,sizeof(struct book),1,fp);
switch (store_id)
{
case 'C':
{
for (i=0;i<3;i++)
{
if (strcmp(temp.kind,press_store[0].kind[i])==0)
{
break;
}
}
if(i==3)
{
printf("error in C!\n");
return NULL;
}
//库存不足
if (temp.lib_num<num)
{
//现存部分全部采购
num=temp.lib_num;
temp.lib_num=0;
//转再版
repress(press_id,cursor_name,num-temp.lib_num);
//再版后通知书店来订购
store_scrimbe(store_id,press_id,cursor_name,press_store[0].scrimbe_num[i]);
}
else
{
temp.lib_num=temp.lib_num-num;
}
a_book->press_id=temp.press_id;
a_book->kind=temp.kind;
a_book->cursor_name=temp.cursor_name;
a_book->name_id=temp.name_id;
a_book->lib_num=num;
a_book->f_y_n=temp.f_y_n;
a_book->g_y_n=temp.g_y_n;
fseek(fp,-sizeof(struct book),1);
fwrite(&temp,sizeof(struct book),1,fp);
break;
}
case 'D':
{
for (i=0;i<4;i++)
{
if (strcmp(temp.kind,press_store[1].kind[i])==0)
{
break;
}
}
if(i==4)
{
printf("error in D!\n");
return NULL;
}
//库存不足
if (temp.lib_num<num)
{
//现存部分全部采购
num=temp.lib_num;
temp.lib_num=0;
//转再版
repress(press_id,cursor_name,num - temp.lib_num);
//再版后通知书店来订购
store_scrimbe(store_id,press_id,cursor_name,press_store[1].scrimbe_num[i]);
}
else
{
temp.lib_num=temp.lib_num-num;
}
a_book->press_id=temp.press_id;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -