int main ()
{
   
   // testing for all possible good and bad data

   // testing with good data 
   bank_account* b = create_account("Ploni Amoni", 250000, "0123456789876");

/* ALL OF THESE WITH BAD DATA "WORK" BY DISPLAYING GUIDING MESSAGES TO THE USER WITHOUT BOMBING OUT THE SYSTEM */
      
   // testing with incorrect account name
   // Running caused Segmentation fault (core dumped)
   // bank_account* b = create_account("", 150000, "0123456789876");

   // testing with incorrect amount
   // error: causes a Segmentation fault (core dumped)
   // bank_account* b = create_account("Bais Hillel", -100, "0123456789876");

   // testing with incorrect account_num length
   // bank_account* b = create_account("Bais Hillel", 150000, "0123456789");
   
   // testing with incorrect account_num chars instead of ints
   //bank_account* b = create_account("Bais Hillel", 250000, "01A3B5C7D9E7F");


/* MUST HANDLE EACH OF THESE CASES THAT BOMBED OUT!!! */

   // testing with incorrect number of parameters
   // bank_account* b = create_account("Bais Hillel", 0123456789876);
   
   // error:  with "badamount": incompatible type for argument 2 of âcreate_accountâ
   // bank_account.h:20: note: expected âdoubleâ but argument is of type âchar *â

   // bank_account* b = create_account("Bais Hillel", "badamount", "0123456789876");

   // error with badamount:  âbadamountâ undeclared (first use in this function)

   //bank_account* b = create_account("Bais Hillel", badamount, "0123456789876");


   if(b == NULL)
   {
      printf("Invalid account");   
   }
   
   if(b->balance < 0)            
   {
      printf("Invalid account");
   }
     
   else
   {
      display_account(b);
      delete_account(b);
   }
   
   return 0;
}
Beispiel #2
0
void do_ban( char_data* ch, char* argument )
{
  account_data*   account;
  ban_data*           ban;
  pfile_data*       pfile  = NULL;
  int               flags;
  int                   i;
  bool              first  = TRUE;
  const char*        name;
  player_data*     victim;

  if( !get_flags( ch, argument, &flags, "srn", "Ban" ) )
    return;

  if( is_set( &flags, 2 ) ) {
    if( *argument == '\0' ) {
      if( badname_array == NULL ) {
        send( ch, "The badname array is empty.\n\r" );
        }
      else {
        display_array( ch, "Bad Name Array", &badname_array[0],
          &badname_array[1], max_badname );
        }
      return;
      }
    i = pntr_search( badname_array, max_badname, argument );
    if( is_set( &flags, 1 ) ) {
      if( i < 0 ) {
        send( ch, "The name '%s' wasn't in the badname array.\n\r",
          argument );
        }
      else {
        record_delete( sizeof( char* ), MEM_BADNAME );
        remove( badname_array, max_badname, i );
        send( ch, "Name removed from badname array.\n\r" );
        save_badname( );
        }
      }
    else {
      if( i > 0 ) {
        send( ch, "The name '%s' is already in the badname array.\n\r",
          argument );
        }
      else if( check_parse_name( ch->link, argument ) ) {
        i = -i-1;
        record_new( sizeof( char* ), MEM_BADNAME );
        name = alloc_string( argument, MEM_BADNAME );
        insert( badname_array, max_badname, name, i );
        send( ch, "The name '%s' is added to the badname array.\n\r",
          name );
        save_badname( );
        }
      }
    return;
    }

  if( is_set( &flags, 0 ) ) {
    if( *argument == '\0' ) {
      page_title( ch, "Banned Sites" );
      for( ban = ban_list; ban != NULL; ban = ban->next )
        page( ch, "%s\n\r", ban->name );
      return;
      }
    if( !is_set( &flags, 1 ) ) {
      for( ban = ban_list; ban != NULL; ban = ban->next ) {
        if( !strcasecmp( argument, ban->name ) ) {
          send( "That site is already banned!\n\r", ch );
          return;
          }
        }
      ban        = new ban_data;
      ban->name  = alloc_string( argument, MEM_BAN );
      save_banned( );
      send( ch, "Ok.\n\r" );
      }
    else {
      for( ban = ban_list; ban != NULL; ban = ban->next ) {
        if( !strcasecmp( argument, ban->name ) ) {
          delete ban;
          save_banned();
          send( ch, "Ok.\n\r" );
          return;
          }
        }
      send( ch, "Site is not banned.\n\r" );
      }
    return;
    }

  if( *argument == '\0' ) {
    page_title( ch, "Banned Accounts" );
    for( i = 0; i < max_account; i++ )
      if( account_list[i]->banned != -1 ) 
        display_account( ch, account_list[i], first );
    return;
    }

  if( ( account = account_arg( argument ) ) == NULL ) {
    if( ( pfile = player_arg( argument ) ) == NULL ) {
      send( ch, "No such account or player.\n\r" );
      return;
      }
    if( ( account = pfile->account ) == NULL ) {
      send( ch, "That player doesn't have an account which makes banning\
 it difficult.\n\r" );
      return;
      }
    }