Advertisement
Guest User

s

a guest
Jul 5th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <conio.h>
  5.  
  6. struct info1 {
  7.  
  8. int cp;
  9. char dp[36];
  10. int nd;
  11. int st;
  12. };
  13.  
  14. struct info2 {
  15.  
  16. int cpp;
  17. int cuv;
  18. };
  19.  
  20. int leerarchivo (struct info1[]);
  21. void inicializa (int[]);
  22. int actualizar (struct info1[],int,int[]);
  23. int buscar (struct info1[],int,int);
  24. void funcionptob (int[]);
  25. void funcionptoc (struct info1[],int);
  26.  
  27. int main()
  28. {
  29.     struct info1 vec[3000];
  30.     int cant,nd[20],cp;
  31.  
  32.     cant=leerarchivo(vec);
  33.     inicializa(nd);
  34.     cant=actualizar(vec,cant,nd);
  35.     buscar(vec,cant,cp);
  36.     funcionptob(nd);
  37.     funcionptoc (vec,cant);
  38.  
  39.     return 0;
  40. }
  41.  
  42. int leerarchivo(struct info1 v[])
  43. {
  44.     FILE*pf;
  45.     int i;
  46.  
  47.     pf=fopen("productos.dat","rb");
  48.     i=0;
  49.     if(pf==NULL)
  50.         {
  51.             printf("ERROR \n");
  52.             exit(0);
  53.         }
  54.         else
  55.             {
  56.                 fread(&v[i],sizeof(struct info1),1,pf);
  57.  
  58.                 while (!feof(pf))
  59.                     {
  60.                         i++;
  61.                         fread(&v[i],sizeof(struct info1),1,pf);
  62.                     }
  63.             }
  64.         fclose(pf);
  65.         return i;
  66. }
  67. void inicializa(int nd[])
  68. {
  69.     int i;
  70.  
  71.     for (i=0;i<20;i++)
  72.     {
  73.         nd[i]=0;
  74.     }
  75. }
  76. int actualizar(struct info1 v[],int c,int nd[])
  77. {
  78.     FILE*fp;
  79.     struct info2 aux;
  80.     int antcp,sum,pos;
  81.  
  82.     fp=fopen("pedidos.dat","rb");
  83.     if (fp==NULL)
  84.         {
  85.             printf("ERROR \n");
  86.             exit(0);
  87.         }
  88.             else
  89.                 {
  90.                     fread(&aux,sizeof(aux),1,fp);
  91.  
  92.                     while (!feof(fp))
  93.                     {
  94.                         antcp=aux.cpp;
  95.                         sum=0;
  96.                         pos=buscar(v,c,aux.cpp);
  97.  
  98.                             while (!feof(fp)&&antcp==aux.cpp)
  99.                                 {
  100.                                     if (pos==-1)
  101.                                         {
  102.                                             v[c].cp=aux.cpp;
  103.                                             printf("ingrese descripcion del producto: \n");
  104.                                             fflush(stdin);
  105.                                             gets(v[c].dp);
  106.                                             printf("ingrese el numero de deposito: \n");
  107.                                             scanf("%d",&v[c].nd);
  108.                                             v[c].st-=aux.cuv;
  109.                                             c++;
  110.                                         }
  111.                                             else
  112.                                             {
  113.                                                 printf("ERROR \n");
  114.                                             }
  115.                                             if (pos!=-1)
  116.                                                 {
  117.  
  118.                                                 if (v[pos].st>=aux.cuv)
  119.                                                 {
  120.                                                    v[pos].st-=aux.cuv;
  121.                                                    sum+=aux.cuv;
  122.                                                    nd[v[pos].nd-1]+=aux.cuv;
  123.                                                 }
  124.                                                 else
  125.                                                     {
  126.                                                      printf("RECHAZADO \n");
  127.                                                     }
  128.                                                 }
  129.                                 }
  130.                                     fread(&aux,sizeof(aux),1,fp);
  131.                                 }
  132.  
  133.                     printf("Codigo de producto: %d \n",antcp);
  134.                     printf("unidades vendidas: %d \n",sum);
  135.  
  136.  
  137.                 }
  138.                  fclose(fp);
  139.                  return c;
  140. }
  141. int buscar (struct info1 v[],int cp,int c)
  142. {
  143.     int pos,i,antcp;
  144.  
  145.     pos=-1;
  146.     i=0;
  147.  
  148.     while (pos==-1&&i<c)
  149.         {
  150.  
  151.             if (v[i].cp==antcp)
  152.             {
  153.             pos=i;
  154.             }
  155.             else
  156.             {
  157.                 i++;
  158.             }
  159.         }
  160.         return pos;
  161. }
  162. void funcionptob(int nd[])
  163. {
  164.     int ban,i,may,maypos;
  165.  
  166.     ban=0;
  167.  
  168.     for (i=0;i<20;i++)
  169.         {
  170.             if
  171.                 (ban==0 || nd[i]>may)
  172.                 {
  173.                     may=nd[i];
  174.                     maypos=i;
  175.                     ban=1;
  176.                 }
  177.  
  178.         }
  179.         printf("el numero de deposito en el que se vendieron mas unidades fue en el: %d \n",maypos+1);
  180. }
  181. void funcionptoc(struct info1 v[],int c)
  182. {
  183.     FILE*pt;
  184.     int i;
  185.  
  186.     pt=fopen("sin stock","wb");
  187.  
  188.     if (pt==NULL)
  189.         {
  190.             printf("ERROR \n");
  191.             exit (0);
  192.         }
  193.         else
  194.         {
  195.             for (i=0;i<c;i++)
  196.             {
  197.                 if (v[i].st==0)
  198.                 {
  199.                     fwrite(&v[i],sizeof(struct info1),1,pt);
  200.                 }
  201.             }
  202.         }
  203.         fclose(pt);
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement