void run_transactions(Account accounts[], int length,char* fileName){
	FILE *ptr;
	ptr =fopen(fileName,"r");
	if (!ptr){
        	return;
	}
	int id;
	float transaction;
	Account * acc;
	while(fscanf(ptr, "%d %f", &id, &transaction)!=EOF){
		acc=find_account(accounts, 0,length-1 ,id);
		if(acc==NULL){
			printf("Invalid transaction; account %d does not exist\n",id);
			continue;		
		}
		if((accounts[id-1].balance)+transaction<0){
			printf("Invalid transaction; Withdrawing %f from account %d results in a negative balance\n",transaction,id);
			
		}else{
			accounts[id-1].balance=accounts[id-1].balance+transaction;
		}
		
		
	}
	
}
Account* find_account(Account accounts[], int low, int high,int key){
	if(high<low){
		return NULL;	
	}else{
		int mid=(low+high)/2;
		int midVal=accounts[mid].accountId;
		//printf("%d",midVal);
		if(midVal>key){
			return find_account(accounts,low,mid-1,key);
		}else if(midVal<key){
			return find_account(accounts,mid+1,high,key);
		}else{
			return &accounts[mid];
		}	
	}

}
Пример #3
0
void
Opal::Bank::on_mwi_event (std::string aor,
			  std::string info)
{
  AccountPtr account = find_account (aor);

  if (account)
    account->handle_message_waiting_information (info);
}
Пример #4
0
void
Opal::Bank::on_registration_event (std::string aor,
				   Opal::Account::RegistrationState state,
				   std::string msg)
{
  AccountPtr account = find_account (aor);

  if (account)
    account->handle_registration_event (state, msg);
}
Пример #5
0
static void
account_manager_ready_for_accounts_cb (GObject *source_object,
    GAsyncResult *result,
    gpointer user_data)
{
  TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
  GError *error = NULL;
  GApplication *app = G_APPLICATION (user_data);

  if (!tp_proxy_prepare_finish (manager, result, &error))
    {
      DEBUG ("Failed to prepare account manager: %s", error->message);
      g_clear_error (&error);
      goto out;
    }

  if (selected_account_name != NULL)
    {
      gchar *account_path;
      TpAccount *account;

      /* create and prep the corresponding TpAccount so it's fully ready by the
       * time we try to select it in the accounts dialog */
      if (g_str_has_prefix (selected_account_name, TP_ACCOUNT_OBJECT_PATH_BASE))
        account_path = g_strdup (selected_account_name);
      else
        account_path = g_strdup_printf ("%s%s", TP_ACCOUNT_OBJECT_PATH_BASE,
            selected_account_name);

      account = find_account (manager, account_path);

      if (account != NULL)
        {
          empathy_accounts_show_accounts_ui (manager, account, app);
          goto out;
        }
      else
        {
          DEBUG ("Failed to find account with path %s", account_path);

          g_clear_error (&error);

          maybe_show_accounts_ui (manager, app);
        }

      g_free (account_path);
    }
  else
    {
      maybe_show_accounts_ui (manager, app);
    }

out:
  g_application_release (app);
}