コード例 #1
0
int main() {
    if (0 == data_input("input.txt")) {
        result = unique_char(str_src);
        if (0 == data_output("output.txt")) {
            return 0;
        }
    }
    return 1;
}
コード例 #2
0
int main() {
    if (0 == data_input("input.txt")) {
        result = plus(num_a, num_b);
        if (0 == data_output("output.txt")) {
            return 0;
        }
    }
    return 1;
}
コード例 #3
0
int main() {
    if (0 == data_input("input.txt")) {
        selection_sort(data, length);
        if (0 == data_output("output.txt")) {
            return 0;
        }
    }
    return 1;
}
コード例 #4
0
int main() {
    if (0 == data_input("input.txt")) {
        shuffle(data, length);
        quick_sort(data, 0, length - 1);
        if (0 == data_output("output.txt")) {
            return 0;
        }
    }
    return 1;
}
コード例 #5
0
ファイル: main.c プロジェクト: chozekun/opsoup
int main(int argc, char **argv) {
    opsoup_t ctx;
    int round = 1;
    FILE *f;

    o = &ctx;
    memset(o, 0, sizeof (opsoup_t));

    if(argc == 2 && strcmp(argv[1], "-v") == 0)
        o->verbose = 1;

    if(image_load() != 0)
        return 1;

    init_sync();

    dis_pass1();

    while(dis_pass2(round)) {
        o->nref = 0;
        round++;
    }

    label_reloc_upgrade();

    label_gen_names();

    label_sort();

    f = fopen(OUTPUT_FILE, "w");
    if(f == NULL) {
        printf("main: couldn't open '" OUTPUT_FILE "' for writing: %s\n", strerror(errno));
        return 1;
    }

    label_extern_output(f);

    dis_pass3(f);

    data_output(f);
    data_bss_output(f);

    fclose(f);

    //label_print_unused();

    return 0;
}
コード例 #6
0
ファイル: MES.cpp プロジェクト: haiy/test_project
/*main需要另外调整*/
int main(char argc,char *argv[])
{
	int len;
	int *res=data_input(10230023,&len);
	int i=0;
	printf("len:%d\n",len);
	for(i=0;i<len;i++)
	{
		printf("%d now %d\n",i,res[i]);
	}
	getchar();
	int *output=(int *)malloc(sizeof(int)*len);
	product(res,output,len);
	int fn=data_output(output,len);
	printf("%d\n",fn);
	free(res);
	free(output);
	getchar();
}
コード例 #7
0
ファイル: typetest.cpp プロジェクト: Bluehorn/wxPython
void MyApp::DoStreamDemo(wxCommandEvent& WXUNUSED(event))
{
    wxTextCtrl& textCtrl = * GetTextCtrl();

    textCtrl.Clear();
    textCtrl << _T("\nTest fstream vs. wxFileStream:\n\n");

    textCtrl.WriteText( _T("Writing to ofstream and wxFileOutputStream:\n") );

    wxSTD ofstream std_file_output( "test_std.dat" );
    wxFileOutputStream file_output( file_name );
    wxBufferedOutputStream buf_output( file_output );
    wxTextOutputStream text_output( buf_output );

    wxString tmp;
    signed int si = 0xFFFFFFFF;
    tmp.Printf( _T("Signed int: %d\n"), si );
    textCtrl.WriteText( tmp );
    text_output << si << _T("\n");
    std_file_output << si << "\n";

    unsigned int ui = 0xFFFFFFFF;
    tmp.Printf( _T("Unsigned int: %u\n"), ui );
    textCtrl.WriteText( tmp );
    text_output << ui << _T("\n");
    std_file_output << ui << "\n";

    double d = 2.01234567890123456789;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );
    text_output << d << _T("\n");
    std_file_output << d << "\n";

    float f = (float)0.00001;
    tmp.Printf( _T("Float: %f\n"), f );
    textCtrl.WriteText( tmp );
    text_output << f << _T("\n");
    std_file_output << f << "\n";

    wxString str( _T("Hello!") );
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );
    text_output << str << _T("\n");
    std_file_output << str.ToAscii() << "\n";

    textCtrl.WriteText( _T("\nReading from ifstream:\n") );

    wxSTD ifstream std_file_input( "test_std.dat" );

    std_file_input >> si;
    tmp.Printf( _T("Signed int: %d\n"), si );
    textCtrl.WriteText( tmp );

    std_file_input >> ui;
    tmp.Printf( _T("Unsigned int: %u\n"), ui );
    textCtrl.WriteText( tmp );

    std_file_input >> d;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );

    std_file_input >> f;
    tmp.Printf( _T("Float: %f\n"), f );
    textCtrl.WriteText( tmp );

    char std_buf[200];
    std_file_input >> std_buf;
    str = wxString::FromAscii(std_buf);
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );

    textCtrl.WriteText( _T("\nReading from wxFileInputStream:\n") );

    buf_output.Sync();

    wxFileInputStream file_input( file_name );
    wxBufferedInputStream buf_input( file_input );
    wxTextInputStream text_input( file_input );

    text_input >> si;
    tmp.Printf( _T("Signed int: %d\n"), si );
    textCtrl.WriteText( tmp );

    text_input >> ui;
    tmp.Printf( _T("Unsigned int: %u\n"), ui );
    textCtrl.WriteText( tmp );

    text_input >> d;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );

    text_input >> f;
    tmp.Printf( _T("Float: %f\n"), f );
    textCtrl.WriteText( tmp );

    text_input >> str;
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );



    textCtrl << _T("\nTest for wxDataStream:\n\n");

    textCtrl.WriteText( _T("Writing to wxDataOutputStream:\n") );

    file_output.SeekO( 0 );
    wxDataOutputStream data_output( buf_output );

    wxInt16 i16 = (unsigned short)0xFFFF;
    tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
    textCtrl.WriteText( tmp );
    data_output.Write16( i16 );

    wxUint16 ui16 = 0xFFFF;
    tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
    textCtrl.WriteText( tmp );
    data_output.Write16( ui16 );

    d = 2.01234567890123456789;
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );
    data_output.WriteDouble( d );

    str = _T("Hello!");
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );
    data_output.WriteString( str );

    buf_output.Sync();

    textCtrl.WriteText( _T("\nReading from wxDataInputStream:\n") );

    file_input.SeekI( 0 );
    wxDataInputStream data_input( buf_input );

    i16 = data_input.Read16();
    tmp.Printf( _T("Signed int16: %d\n"), (int)i16 );
    textCtrl.WriteText( tmp );

    ui16 = data_input.Read16();
    tmp.Printf( _T("Unsigned int16: %u\n"), (unsigned int) ui16 );
    textCtrl.WriteText( tmp );

    d = data_input.ReadDouble();
    tmp.Printf( _T("Double: %f\n"), d );
    textCtrl.WriteText( tmp );

    str = data_input.ReadString();
    tmp.Printf( _T("String: %s\n"), str.c_str() );
    textCtrl.WriteText( tmp );
}
コード例 #8
0
ファイル: bacterias.cpp プロジェクト: meithan/bacterias
int main (int argc, char** argv) {

  char strbuf[256];
  time_t raw_time;

  // Load parameters from the specified file
  if (argc != 2) {
    printf("Error! Must provide a parameters filename as first argument\n");
    exit(EXIT_FAILURE);
  } else {
    raw_time = time(NULL);
    printf(">> %s", ctime(&raw_time));
  }
  params_fname = new char[strlen(argv[1])];
  strcpy(params_fname, argv[1]);
  printf(">> Reading parameters file %s ...\n", params_fname);
  load_parameters(params_fname);
  
  const int report_interval = (num_cycles > 100 ? num_cycles : 100) / 100; 
  
  // Open log and data files
  log_file = fopen(log_fname,"w");
  output_file = fopen(output_fname,"w");
  printf(">> Opened log file %s\n", log_fname);
  raw_time = time(NULL);
  sprintf(strbuf, ">> %s", ctime(&raw_time)); log(strbuf, false);
  sprintf(strbuf, ">> Read parameters file %s ...\n", params_fname); log(strbuf, false);

  // Report parameters
  sprintf(strbuf, "grid_size = %i\n", grid_size); log(strbuf);
  sprintf(strbuf, "num_cycles = %i\n", num_cycles); log(strbuf);
  sprintf(strbuf, "growth_multiplier = %f\n", growth_multiplier); log(strbuf);
  sprintf(strbuf, "global_death_rate = %f\n", global_death_rate); log(strbuf);
  sprintf(strbuf, "all_die = %s\n", all_die ? "true" : "false"); log(strbuf);
  sprintf(strbuf, "report_to_screen = %s\n", report_to_screen ? "true" : "false"); log(strbuf);
  sprintf(strbuf, "log_fname = %s\n", log_fname); log(strbuf);
  sprintf(strbuf, "output_fname = %s\n", output_fname); log(strbuf);
  sprintf(strbuf, "output_interval = %i\n", output_interval); log(strbuf);
  sprintf(strbuf, "num_strains = %i\n", num_strains); log(strbuf);
  sprintf(strbuf, "strains_fname = %s\n", strains_fname); log(strbuf);
  sprintf(strbuf, "enable_antagonism = %s\n", enable_antagonism ? "true" : "false"); log(strbuf);
  sprintf(strbuf, "antagonism_table_fname = %s\n", antagonism_table_fname); log(strbuf);
  sprintf(strbuf, "use_real_growth = %s\n", use_real_growth ? "true" : "false"); log(strbuf);
  sprintf(strbuf, "growth_intercept = %f\n", growth_intercept); log(strbuf);
  sprintf(strbuf, "growth_slope = %f\n", growth_slope); log(strbuf);
  sprintf(strbuf, "food_source_rations = %i\n", food_source_rations); log(strbuf);
  sprintf(strbuf, "food_source_radius = %i\n", food_source_radius); log(strbuf);
  sprintf(strbuf, "food_source_spawn_rate = %f\n", food_source_spawn_rate); log(strbuf);
  sprintf(strbuf, "start_population_per_strain = %i\n", start_population_per_strain); log(strbuf);
  sprintf(strbuf, "start_num_food_sources = %i\n", start_num_food_sources); log(strbuf);
  log(">> Parameters loaded successfully\n");

  // Allocate data arrays
  do_allocations();
  log(">> Data arrays allocated\n");
  
  // Set RNG seed
  reset_seed();
  sprintf(strbuf, ">> RNG seed: %u\n", global_seed); log(strbuf);
  
  // Create strains using data from file
  log(">> Loading strains ...\n");
  create_strains();
  
  // Load antagonism matrix (if applicable)
  if (enable_antagonism) {
    log(">> Antagonisms ENABLED\n");
    load_antagonisms();
  } else {
    log(">> Antagonisms DISABLED\n");
  }

  // Compute growth_rates if not using real ones
  if (use_real_growth) {
    log(">> Using measured growth rates\n");
  } else {
    log(">> Computing growth rates from sender degrees ...\n");
    compute_growth_rates();
  }
  
  // Report strains
  log(">> Loaded strains:\n");
  log("(name | sender degree | receiver degree | growth rate)\n");
  int max_length = 0;
  int max_size = 0;
  for (int i = 0; i < num_strains; i++) {
    if (strains[i]->name.length() > max_length)
      max_length = strains[i]->name.length();
    if (strains[i]->sender_degree > max_size)
      max_size = strains[i]->sender_degree;
    if (strains[i]->receiver_degree > max_size)
      max_size = strains[i]->receiver_degree;      
  }
  max_size = int(log10(max_size))+1;
  for (int i = 0; i < num_strains; i++) {
    sprintf(strbuf, "%-*s | %*i | %*i | %.6f\n", max_length, strains[i]->name.c_str(), max_size, strains[i]->sender_degree, max_size, strains[i]->receiver_degree, strains[i]->growth_rate); log(strbuf);
  }
  
  // Create starting bacteria
  bac_counter = 0;
  log(">> Creating bacteria ...\n");
  create_starting_bacteria();
  sprintf(strbuf, "Population: %i\n", (int)bacteria_list.size()); log(strbuf);
  compute_strain_counts();
  
  // Create food sources
  log(">> Creating food sources ...\n");
  create_starting_food();
  sprintf(strbuf, "Food sources: %i\n", (int)food_list.size()); log(strbuf);
  flag_bacteria_at_food_sources();

  // Ready!
  log(">> READY. Starting simulation ...\n", true);
  if (!report_to_screen) {
    printf("(no further output written to screen)\n");
  }
 
  // Main loop over cycles
  for (cycle = 1; cycle <= num_cycles; cycle++) {

    move_bacteria();

    flag_bacteria_at_food_sources();

    food_sources_interactions();

    cleanup_empty_food_sources();

    kill_bacteria();

    cleanup_dead_bacteria();
    
    spawn_food_source();

    compute_strain_counts();
    
    sprintf(strbuf, "Cycle %i, %i bacteria, %i sources\n", cycle, (int)bacteria_list.size(), (int)food_list.size());
    log(strbuf, false);
    if (report_to_screen) {
      if (cycle % report_interval == 0) {
        printf(">> Cycle %i, %i bacteria, %i sources\n", cycle, (int)bacteria_list.size(), (int)food_list.size());
      }
    }
    
    if (cycle % output_interval == 0) {
      data_output();
    }

  }
  
  raw_time = time(NULL);
  sprintf(strbuf, ">> %s", ctime(&raw_time)); log(strbuf, true);
  
  deallocate();
  
}