예제 #1
0
customer cu_init(char *name, int id, double c_limit) {
  customer cu = malloc(sizeof(struct customer));

  /* Copy the name  */
  char *name_cpy = malloc((strlen(name) + 1) * sizeof(char));
  strcpy(name_cpy, name);
  cu->name = name_cpy;

  /* Copy the id and credit limit */
  cu->id = id;
  cu->c_limit = c_limit;

  /* Initalize the amount spent to 0*/
  cu->spent = 0;

  /* Signifies if the customer has an open order */
  cu->open_order = 1;

  /* Initalize compelted order array */
  cu->comp_orders = str_array_init();
  cu->rej_orders = str_array_init();

  /* Create the mutex for this object */
  pthread_mutex_init(&cu->mutex, 0);


  return cu;
}
예제 #2
0
void
str_array_copy(dynamic_string_array *dst,const dynamic_string_array *src)
{
    str_array_init(dst);
    int i;
    for(i=0;i<src->used;++i){
        str_array_addnew(dst,src->head[i]);
    }
}