Advertisement
Guest User

Untitled

a guest
Oct 10th, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1.  
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. void imprimir(void *articulos){
  9.  
  10.  
  11. void ***auxArticulos = (void ***)articulos;
  12. int i = 0;
  13. while (auxArticulos[i]){
  14. char *nombre1 = (char *)auxArticulos[i][0];
  15. char *nombre2 = (char *)auxArticulos[i][1];
  16. int *cantidad = (int *)auxArticulos[i][2];
  17. double *precio = (double *)auxArticulos[i][3];
  18. printf("%s %s %d %.2lf\n",nombre1,nombre2,cantidad[0],precio[0]);
  19. i++;
  20. }
  21.  
  22. }
  23.  
  24.  
  25. void procesarLinea(char *linea,char *&Descripcion,int &cantStock, double &pu){
  26.  
  27. char *ptr, *auxPalabras[500] ;
  28. int contPalabras = 0;
  29. ptr = strtok(linea," ");
  30. auxPalabras[contPalabras++] = ptr;
  31. while (ptr != NULL){
  32. ptr = strtok(NULL," ");
  33. if(ptr != NULL) auxPalabras[contPalabras++] = ptr;
  34. }
  35.  
  36. pu = atof(auxPalabras[contPalabras-1]);
  37. cantStock = atoi (auxPalabras[contPalabras-2]);
  38.  
  39. char palabra[600] = "";
  40. for (int i=0; i<contPalabras-2;i++){
  41. strcat(palabra,auxPalabras[i]);
  42. strcat(palabra," ");
  43. }
  44. Descripcion = new char [strlen(palabra)+1];
  45. strcpy(Descripcion,palabra);
  46.  
  47. }
  48.  
  49.  
  50. void leeArticulos(void *&articulos){
  51.  
  52.  
  53. char *Descripcion,codigo[40],linea[500], *codDin;
  54. int cantStock, *stock, pos=0, cant = 0, aux;
  55. double pu, *puDin;
  56. void **auxVoid, **exacto = NULL;
  57.  
  58. while (1){
  59. scanf("%s",codigo);
  60. if (strcmp(codigo,"VENTAS:") == 0) break;
  61. scanf("%d",&aux); gets(linea);
  62. procesarLinea(linea,Descripcion,cantStock,pu);
  63. stock = new int; *stock = cantStock;
  64. puDin = new double; *puDin = pu;
  65. codDin = new char [strlen(codigo)+1];
  66. strcpy(codDin,codigo);
  67. void ** registro = new void *[4];
  68. registro[0] = codDin; registro[1] = Descripcion;
  69. registro[2] = stock; registro[3] = puDin;
  70. if (pos == cant){
  71. auxVoid = new void *[cant+5];
  72. for (int i=0; i<pos; i++) auxVoid[i] = exacto[i];
  73. if (exacto!= NULL) delete[] exacto;
  74. exacto = auxVoid;
  75. cant+=5;
  76. }
  77. exacto[pos] = registro; pos++;
  78. exacto[pos] = NULL;
  79. }
  80. articulos = auxVoid;
  81. }
  82.  
  83. int main(int argc, char** argv) {
  84.  
  85. void *articulos = NULL;
  86.  
  87. leeArticulos(articulos);
  88. imprimir(articulos);
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement