Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- struct info1 {
- int cp;
- char dp[36];
- int nd;
- int st;
- };
- struct info2 {
- int cpp;
- int cuv;
- };
- int leerarchivo (struct info1[]);
- void inicializa (int[]);
- int actualizar (struct info1[],int,int[]);
- int buscar (struct info1[],int,int);
- void funcionptob (int[]);
- void funcionptoc (struct info1[],int);
- int main()
- {
- struct info1 vec[3000];
- int cant,nd[20],cp;
- cant=leerarchivo(vec);
- inicializa(nd);
- cant=actualizar(vec,cant,nd);
- buscar(vec,cant,cp);
- funcionptob(nd);
- funcionptoc (vec,cant);
- return 0;
- }
- int leerarchivo(struct info1 v[])
- {
- FILE*pf;
- int i;
- pf=fopen("productos.dat","rb");
- i=0;
- if(pf==NULL)
- {
- printf("ERROR \n");
- exit(0);
- }
- else
- {
- fread(&v[i],sizeof(struct info1),1,pf);
- while (!feof(pf))
- {
- i++;
- fread(&v[i],sizeof(struct info1),1,pf);
- }
- }
- fclose(pf);
- return i;
- }
- void inicializa(int nd[])
- {
- int i;
- for (i=0;i<20;i++)
- {
- nd[i]=0;
- }
- }
- int actualizar(struct info1 v[],int c,int nd[])
- {
- FILE*fp;
- struct info2 aux;
- int antcp,sum,pos;
- fp=fopen("pedidos.dat","rb");
- if (fp==NULL)
- {
- printf("ERROR \n");
- exit(0);
- }
- else
- {
- fread(&aux,sizeof(aux),1,fp);
- while (!feof(fp))
- {
- antcp=aux.cpp;
- sum=0;
- pos=buscar(v,c,aux.cpp);
- while (!feof(fp)&&antcp==aux.cpp)
- {
- if (pos==-1)
- {
- v[c].cp=aux.cpp;
- printf("ingrese descripcion del producto: \n");
- fflush(stdin);
- gets(v[c].dp);
- printf("ingrese el numero de deposito: \n");
- scanf("%d",&v[c].nd);
- v[c].st-=aux.cuv;
- c++;
- }
- else
- {
- printf("ERROR \n");
- }
- if (pos!=-1)
- {
- if (v[pos].st>=aux.cuv)
- {
- v[pos].st-=aux.cuv;
- sum+=aux.cuv;
- nd[v[pos].nd-1]+=aux.cuv;
- }
- else
- {
- printf("RECHAZADO \n");
- }
- }
- }
- fread(&aux,sizeof(aux),1,fp);
- }
- printf("Codigo de producto: %d \n",antcp);
- printf("unidades vendidas: %d \n",sum);
- }
- fclose(fp);
- return c;
- }
- int buscar (struct info1 v[],int cp,int c)
- {
- int pos,i,antcp;
- pos=-1;
- i=0;
- while (pos==-1&&i<c)
- {
- if (v[i].cp==antcp)
- {
- pos=i;
- }
- else
- {
- i++;
- }
- }
- return pos;
- }
- void funcionptob(int nd[])
- {
- int ban,i,may,maypos;
- ban=0;
- for (i=0;i<20;i++)
- {
- if
- (ban==0 || nd[i]>may)
- {
- may=nd[i];
- maypos=i;
- ban=1;
- }
- }
- printf("el numero de deposito en el que se vendieron mas unidades fue en el: %d \n",maypos+1);
- }
- void funcionptoc(struct info1 v[],int c)
- {
- FILE*pt;
- int i;
- pt=fopen("sin stock","wb");
- if (pt==NULL)
- {
- printf("ERROR \n");
- exit (0);
- }
- else
- {
- for (i=0;i<c;i++)
- {
- if (v[i].st==0)
- {
- fwrite(&v[i],sizeof(struct info1),1,pt);
- }
- }
- }
- fclose(pt);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement