Advertisement
techno-

ListaShared.c

Nov 12th, 2022
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define maxShared 4096
  6.  
  7. typedef struct{
  8.     int *dir;
  9.     int Bytes;
  10.     int month;
  11.     int dia;
  12.     int hora;
  13.     int min;
  14.     char tipo[20];
  15.     int key;
  16. }shared;
  17.  
  18. shared *HistShared[maxShared];
  19.  
  20. int nshared = 0; //Numero de elementos en el array
  21.  
  22. void histSharedInsert(int *dir, int Bytes, int month, int dia, int hora, int min, char *tipo, int key){
  23.    
  24.     if(nshared == maxShared){
  25.         printf("Espacio del historial agotado");
  26.         return;
  27.     }
  28.     else{
  29.         nshared++;
  30.         HistShared[nshared-1]=malloc(sizeof(shared));
  31.         HistShared[nshared-1]->dir=dir;
  32.         HistShared[nshared-1]->Bytes=Bytes;
  33.         HistShared[nshared-1]->month=month;
  34.         HistShared[nshared-1]->dia=dia;
  35.         HistShared[nshared-1]->hora=hora;
  36.         HistShared[nshared-1]->min=min;
  37.         HistShared[nshared-1]->key=key;
  38.         strcpy(HistShared[nshared-1]->tipo,tipo);
  39.     }
  40. }
  41.  
  42. shared *histSharedElemento(int n){
  43.     return HistShared[n];
  44. }
  45.  
  46. int histSharedNumElementos(){
  47.     return nshared;
  48. }
  49.  
  50. void histSharedBorrar(){
  51.     int i;
  52.     for(i=0; i <= nshared; i++){
  53.         free(HistShared[i]);
  54.     }
  55.     nshared = 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement