int main(){ FILE *fp = fopen("Address_book.csv", "r"); if(fp == NULL){ fprintf(stderr, "Can't open file"); exit(1); } clock_t s; // variable for measure time execute float t_qsort, t_qsort_3way; int size_addrr = count_line(fp); // get line (in this case is size of element address book) address_book * addrr_book = get_data_from_file(fp, size_addrr); // get data address_book addrr_book_2[size_addrr]; memcpy(addrr_book_2, addrr_book, sizeof(address_book) * size_addrr); // quicksort 3 way generic s = clock(); qsort_3w_gen(addrr_book_2, size_addrr - 1, sizeof(address_book), compar_address_name); t_qsort_3way = (float)(clock() - s)/CLOCKS_PER_SEC; // quick sort built s = clock(); qsort(addrr_book, size_addrr, sizeof(address_book), compar_address_name); t_qsort = (float)(clock() - s)/CLOCKS_PER_SEC; printf("after sort :\n"); printf("Address book 1\n"); print_addrr_book(addrr_book, size_addrr); printf("Address book 2\n"); print_addrr_book(addrr_book_2, size_addrr); printf("Time run qsort built-in :%f\n", t_qsort); printf("Time run qsort 3 way generic :%f\n", t_qsort_3way); }
void tektextcenter(const char *str, const t_bunny_position *pos, t_bunny_pixelarray *out, t_font *font) { int i; int j; t_bunny_position pix; int sp; pix.y = pos->y - count_line(str, font->font_size); sp = count_space(str, font->font_size, 0); i = 0; j = 0; while (str[i]) { if (str[i] == '\n') { pix.y += font->font_size + font->font_size / 4; j = 0; sp = count_space(str, font->font_size, ++i); } else { pix.x = pos->x + j * font->font_size + (font->font_size / 4) * j - sp; tekchar(out, font, &pix, str[i++]); j++; } } }
int main(){ FILE *fin = fopen(CSV, "r"); if(fin == NULL){ fprintf(stderr, "can't open file %s \n", CSV); exit(1); } int size = count_line(fin); symbol_table book = get_data_from_file(fin, size); print_addrr_book(book); char name_str[25]; printf("Name want to find > "); scanf("%[^\n]", name_str); entry *find = get_entry(name_str, book); if(find == NULL){ printf("Not found %s !!", name_str); } else { printf("%s - %s \n", (char *)(find->key), (char *)(find->value)); } drop_symbol_table(&book); print_addrr_book(book); fclose(fin); return 0; }
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { // Start typing your C/C++ solution below // DO NOT write int main() function vector<vector<int> > &grid = obstacleGrid; vector<vector<int> > count_grid; int num_rows = grid.size(); int num_cols = grid[0].size(); for (int i = 0; i < num_rows; i++) { vector<int> count_line(num_cols, 0); count_grid.push_back(count_line); } for (int i = num_rows-1; i >= 0; i--) { for (int j = num_cols-1; j >= 0; j--) { if (grid[i][j] == 1) { count_grid[i][j] = 0; } else { bool is_end = true; int down = 0, right = 0; if (j < num_cols-1) { right = count_grid[i][j+1]; is_end = false; } if (i < num_rows-1) { down = count_grid[i+1][j]; is_end = false; } count_grid[i][j] = is_end ? 1 : right + down; } } } return count_grid[0][0]; }
int main(){ FILE *fin = fopen(CSV, "r"); if(fin == NULL){ fprintf(stderr, "can't open file %s \n", CSV); exit(1); } int size = count_line(fin); phone_book book = get_data_from_file(fin, size); print_addrr_book(book); char name_str[25]; printf("Name want to find > "); scanf("%[^\n]", name_str); phone_entry *find = find_person_phone_book(name_str, book); if(find == NULL){ printf("Not found %s !!\n", name_str); } else { printf("%s - %s \n", find->name, find->tel); } drop_phone_book(&book); print_addrr_book(book); fclose(fin); return 0; }
int main(int ac, char **av) { t_coor coor; if (ac == 1) ft_putstr("No file\n"); else if (ac == 2) { if ((coor.fd = open(av[1], O_RDONLY)) == -1) { ft_putstr("Can't read the map."); return (0); } count_line(&coor); coor.fd = open(av[1], O_RDONLY); init(&coor); stock_fd(&coor); close(coor.fd); coor.mlx = mlx_init(); coor.win = mlx_new_window(coor.mlx, 1200, 1200, "FdF"); mlx_expose_hook(coor.win, expose_hook, &coor); mlx_key_hook(coor.win, key_hook, &coor); mlx_loop(coor.mlx); } return (0); }
void input_uvp(char str[], double u[], double v[], double p[], double a[NX+1][NY+1][NZ+1], double B[NX+1][NY+1][NZ+1], double w[][N2], int ncell_var) { int i, j, k, n, nnn, dum=-1; char ss[256]; char funcnam[256]="input_uvp"; FILE *fin_uvp; if((fin_uvp = fopen(str, "r")) == NULL) { printf("error: cannot open %s\n", str); exit(1); } n = count_line(fin_uvp); fclose(fin_uvp); fin_uvp=fopen(str, "r"); if (n != ncell_var + 2*(NX+1)*(NY+1)*(NZ+1) + ncell_var) { printf(" error: input data file initial_data is inconsistent\n"); printf("n=%d ncell_var=%d, sum=%d\n", n, ncell_var, ncell_var + 2*(NX+1)*(NY+1)*(NZ+1) + ncell_var); exit(1); } for(i = 0; i < ncell_var; i++) { fgets(ss, sizeof(ss), fin_uvp); nnn=sscanf(ss, "%*d %lf %lf %lf", &(u[i]), &(v[i]), &(p[i])); if (nnn != 3) error_msg(funcnam); } for(i = 0; i <= NX; i++) for(j = 0; j <= NY; j++) for(k = 0; k <= NZ; k++) { fgets(ss, sizeof(ss), fin_uvp); if(sscanf(ss, "%*f %*f %*f %lf", &(a[i][j][k])) != 1) error_msg("2"); } for(i = 0; i <= NX; i++) for(j = 0; j <= NY; j++) for(k = 0; k <= NZ; k++) { fgets(ss, sizeof(ss), fin_uvp); if(sscanf(ss, "%*f %*f %*f %lf", &(B[i][j][k])) != 1) error_msg("3"); } for(i = 0; i < ncell_var; i++) { fscanf(fin_uvp, "%d", &dum); if (dum != i) { error_msg("4"); } for (j = 0; j < N2; j++) { if(fscanf(fin_uvp, "%lf", &(w[i][j])) != 1) { error_msg("5"); } } } fclose(fin_uvp); }
int main(){ btinit(); BTA *t; FILE *fin = fopen(CSV,"r"); if(fin==NULL){ fprintf(stderr,"Cannot open file input %s:%d!!!\n",__FILE__,__LINE__); exit(1); } int size = count_line(fin); btcrt(fid,size,0); t = btopn(fid,0,0); //insert data to tree person *new_info = get_data_from_file(fin,size); add_data_to_tree(t,new_info,size); free(new_info); btcls(t); }
int main(int argc, char *argv[]) { double u[NN], v[NN], p[NN], fat[NN], Vc[NN], w[NN][N2], a[NX+1][NY+1][NZ+1], B[NX+1][NY+1][NZ+1], u_ave[NN]; double xx[NN], yy[NN], zz[NN], r[NN]; double ageb[NN], agek[NN]; int state[NN], div_times[NN], touch[NN]; int lj[NN][N2]; int indx[NN]; // lj[i][0...indx-1] int ljd[NN][N2]; int ljd_indx[NN]; // ljd[i][0...ljd_indx-1] /* debug */ int pair[NN], pair2[NN], pair_indx = 0; double L[NN]; int other_cell[NN]; int tb[NN]; int ncell_var, num; int i, j, k; int KEY_INPUT_DATA; char celldata_name[100]; char str[100], str_chem[100]; FILE *finput, *fdebug; void checkstate(int [], int ); void checkparam(); int nmx = (int)(COMPRESS_FACTOR * LX/(2.0*R_memb)); int nmy = (int)(COMPRESS_FACTOR * LY/(2.0*R_memb)); printf("mkdir %s\n", OUTPUTDIR ); sprintf(str, "mkdir -p %s", OUTPUTDIR); system(str); checkparam(); if (fabs(dx-dh)>EPS || fabs(dy-dh)>EPS || fabs(dz-dh)>EPS) { printf("error: dx=%f dy=%f dz=%f.\n", dx, dy, dz); printf("grid size must be dh=%f.\n", dh); exit(1); } if (argc <= 1) { printf("input file name required\n"); exit(1); } strcpy(celldata_name, argv[1]); if((finput = fopen(celldata_name, "r")) == NULL) { printf("input file error2\n"); exit(1); } if ((num = count_line(finput)) != NN) { printf(" error: input data file not consistent.\n"); printf("input file lines = %d: NN = %d\n", num, NN); exit(5); } fclose(finput); if((finput = fopen(celldata_name, "r")) == NULL) { printf("input file error2\n"); exit(1); } initialize_state(state, ageb, agek, fat, Vc); /* input vales, initialize gj, return first blank cell's index*/ initialize_vars(finput, xx, yy, zz, lj, state, r, ageb, agek, div_times, fat, Vc, touch, L, other_cell, tb, &ncell_var, &NDER, &NMEMB); printf("variables initialized: NDER=%d NMEMB=%d ncell=%d NN=%d\n", NDER, NMEMB, ncell_var, NN); if (nmx != NMX || nmy != NMY) { printf("error: number of membrane particles inconsistent with parameter file\n"); exit(1); } checkstate(state, ncell_var); connect_lj(lj, state, ncell_var, xx, yy, zz, r, indx); printf("lj connection initialized\n"); check_pair(ncell_var, xx, yy, zz, pair, pair2, &pair_indx, L, other_cell); fclose(finput); initial_u(u, v, p, a, B, w); // initialization KEY_INPUT_DATA = atoi(argv[2]); if (KEY_INPUT_DATA != 1 && KEY_INPUT_DATA != 0) { printf("error: 2nd argument must be 0 or 1\n"); exit(3); } if (KEY_INPUT_DATA) { printf("chemical data read from recycled_data\n"); sprintf(str_chem, "recycled_data"); input_uvp(str_chem, u, v, p, a, B, w, ncell_var); } if (SYSTEM == WHOLE) { printf("computing the whole epidermis.\n"); // SYSTEM = WHOLE; } else if (SYSTEM == BASAL) { printf("computing only the basal layer and the dermis.\n"); // SYSTEM = BASAL; } else { printf("parameter SYSTEM must be 'WHOLE' or 'BASAL'\n"); exit(1); } if (KEY_FORCED_SC) printf("forced cornification enabled\n"); else printf("forced cornification disabled\n"); if (KEY_INPUT_DATA && KEY_FORCED_SC) { printf("error: forced cornification must be disabled\n"); exit(1); } else if (!KEY_INPUT_DATA && !KEY_FORCED_SC) { printf("WARNING: sc formation would take longer without forced cornification.\n"); } if (KEY_DERMAL_CHANGE) printf("computing dermal change\n"); else printf("fixed dermal shape\n"); printf("divmax=%d, accel_div=%f MALIGNANT=%d\n", div_max, accel_div, MALIGNANT); printf("K_TOTAL=%f, K_DESMOSOME_RATIO=%f\n", K_TOTAL, K_DESMOSOME_RATIO); evolution(u, v, p, w, a, B, xx, yy, zz, r, ageb, agek, state, div_times, fat, Vc, touch, lj, indx, &ncell_var, u_ave, pair, pair2, &pair_indx, L, other_cell, ljd, ljd_indx, tb); printf("finished\n"); return 0; }
DWORD WINAPI soe_worker_thread_main(LPVOID thread_data) { #else void *soe_worker_thread_main(void *thread_data) { #endif thread_soedata_t *t = (thread_soedata_t *)thread_data; while(1) { uint32 i; /* wait forever for work to do */ #if defined(WIN32) || defined(_WIN64) WaitForSingleObject(t->run_event, INFINITE); #else pthread_mutex_lock(&t->run_lock); while (t->command == SOE_COMMAND_WAIT) { pthread_cond_wait(&t->run_cond, &t->run_lock); } #endif /* do work */ if (t->command == SOE_COMMAND_SIEVE_AND_COUNT) { t->sdata.lines[t->current_line] = (uint8 *)malloc(t->sdata.numlinebytes * sizeof(uint8)); sieve_line(t); t->linecount = count_line(&t->sdata, t->current_line); free(t->sdata.lines[t->current_line]); } else if (t->command == SOE_COMMAND_SIEVE_AND_COMPUTE) { sieve_line(t); } else if (t->command == SOE_COMPUTE_ROOTS) { if (VFLAG > 2) printf("starting root computation over %u to %u\n", t->startid, t->stopid); if (t->sdata.sieve_range == 0) { for (i = t->startid; i < t->stopid; i++) { uint32 inv; uint32 prime = t->sdata.sieve_p[i]; inv = modinv_1(t->sdata.prodN, prime); t->sdata.root[i] = prime - inv; t->sdata.lower_mod_prime[i - t->sdata.bucket_start_id] = (t->sdata.lowlimit + 1) % prime; } } else { mpz_t tmpz; //mpz_t t1, t2; mpz_init(tmpz); //experiment for custom ranges that can be expressed as base^exp + range //mpz_init(t1); //mpz_init(t2); mpz_add_ui(tmpz, *t->sdata.offset, t->sdata.lowlimit + 1); for (i = t->startid; i < t->stopid; i++) { uint32 inv; uint32 prime = t->sdata.sieve_p[i]; inv = modinv_1(t->sdata.prodN, prime); t->sdata.root[i] = prime - inv; t->sdata.lower_mod_prime[i - t->sdata.bucket_start_id] = mpz_tdiv_ui(tmpz, prime); //mpz_set_ui(t2,prime); //mpz_set_ui(t1, 10); //mpz_powm_ui(t1, t1, 999999, t2); //t->sdata.lower_mod_prime[i - t->sdata.bucket_start_id] = mpz_get_ui(t1); } //mpz_clear(t1); //mpz_clear(t2); } } else if (t->command == SOE_COMPUTE_PRIMES) { t->linecount = 0; for (i = t->startid; i < t->stopid; i+=8) { t->linecount = compute_8_bytes(&t->sdata, t->linecount, t->ddata.primes, i, NULL); } } else if (t->command == SOE_COMPUTE_PRPS) { t->linecount = 0; for (i = t->startid; i < t->stopid; i++) { mpz_add_ui(t->tmpz, t->offset, t->ddata.primes[i - t->startid]); if ((mpz_cmp(t->tmpz, t->lowlimit) >= 0) && (mpz_cmp(t->highlimit, t->tmpz) >= 0)) { if (mpz_probab_prime_p(t->tmpz, t->current_line)) t->ddata.primes[t->linecount++] = t->ddata.primes[i - t->startid]; } } } else if (t->command == SOE_COMMAND_END) break; /* signal completion */ t->command = SOE_COMMAND_WAIT; #if defined(WIN32) || defined(_WIN64) SetEvent(t->finish_event); #else pthread_cond_signal(&t->run_cond); pthread_mutex_unlock(&t->run_lock); #endif } #if defined(WIN32) || defined(_WIN64) return 0; #else return NULL; #endif }