Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- using namespace std;
- void imprimir(void *articulos){
- void ***auxArticulos = (void ***)articulos;
- int i = 0;
- while (auxArticulos[i]){
- char *nombre1 = (char *)auxArticulos[i][0];
- char *nombre2 = (char *)auxArticulos[i][1];
- int *cantidad = (int *)auxArticulos[i][2];
- double *precio = (double *)auxArticulos[i][3];
- printf("%s %s %d %.2lf\n",nombre1,nombre2,cantidad[0],precio[0]);
- i++;
- }
- }
- void procesarLinea(char *linea,char *&Descripcion,int &cantStock, double &pu){
- char *ptr, *auxPalabras[500] ;
- int contPalabras = 0;
- ptr = strtok(linea," ");
- auxPalabras[contPalabras++] = ptr;
- while (ptr != NULL){
- ptr = strtok(NULL," ");
- if(ptr != NULL) auxPalabras[contPalabras++] = ptr;
- }
- pu = atof(auxPalabras[contPalabras-1]);
- cantStock = atoi (auxPalabras[contPalabras-2]);
- char palabra[600] = "";
- for (int i=0; i<contPalabras-2;i++){
- strcat(palabra,auxPalabras[i]);
- strcat(palabra," ");
- }
- Descripcion = new char [strlen(palabra)+1];
- strcpy(Descripcion,palabra);
- }
- void leeArticulos(void *&articulos){
- char *Descripcion,codigo[40],linea[500], *codDin;
- int cantStock, *stock, pos=0, cant = 0, aux;
- double pu, *puDin;
- void **auxVoid, **exacto = NULL;
- while (1){
- scanf("%s",codigo);
- if (strcmp(codigo,"VENTAS:") == 0) break;
- scanf("%d",&aux); gets(linea);
- procesarLinea(linea,Descripcion,cantStock,pu);
- stock = new int; *stock = cantStock;
- puDin = new double; *puDin = pu;
- codDin = new char [strlen(codigo)+1];
- strcpy(codDin,codigo);
- void ** registro = new void *[4];
- registro[0] = codDin; registro[1] = Descripcion;
- registro[2] = stock; registro[3] = puDin;
- if (pos == cant){
- auxVoid = new void *[cant+5];
- for (int i=0; i<pos; i++) auxVoid[i] = exacto[i];
- if (exacto!= NULL) delete[] exacto;
- exacto = auxVoid;
- cant+=5;
- }
- exacto[pos] = registro; pos++;
- exacto[pos] = NULL;
- }
- articulos = auxVoid;
- }
- int main(int argc, char** argv) {
- void *articulos = NULL;
- leeArticulos(articulos);
- imprimir(articulos);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement