Пример #1
0
int main(void) 
{
    int n, step, number, matches;
    int position = 1;
    
    matches = scanf("%d", &n);
    check_input(matches);
    
    matches = scanf("%d", &step);
    check_input(matches);
    
    int i;
    for (i = 0; i < n; i++) 
    {
        matches = scanf("%d", &number);
        while (8 > position)
        {
            int mask = 1 << (7 - position);
            number = number | mask;
            position += step;
        }
        
        position = position - 8;
        printf("%d\n", number);
    }

    return 0;
}
Пример #2
0
int main(void)
{
    int size, number, matches, searchNumber;
    
    printf("count of numbers --> ");
    matches = scanf("%d", &size);
    check_input(matches);
    
    int array[size];  
    printf("line numbers --> ");
    
    int i;
    for (i = 0; i < size; i++)
    {
        matches = scanf("%d", &number);
        check_input(matches);
        array[i] = number;
    }

    printf("number for search --> ");
    matches = scanf("%d", &searchNumber);
    check_input(matches);
    
    int result = linear_search(array, size, searchNumber);
    
    printf("result --> %s", result ? "yes" : "no");

    return 0;
}
Пример #3
0
 void matrix_matrix_mult(int m, int n, int k, double alpha, double beta, double* A, double* B, double* C){
   /*
     Calculates C = a*A*B + b*C
     A, B and C need to be matrices in Fortran vector format (single vector, columnwise)
     dimensions: A is m*k, B is k*n, so C has to be m*n
     This is an O(n^3) operation
   */
   check_input(C, A, "matrix_matrix_mult");
   check_input(C, B, "matrix_matrix_mult");
   cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, k, alpha, A, m, B, k, beta, C, m);
 }
Пример #4
0
int sign_up(int sockfd){
	char mesg[LEN];
	char partner[]="0";
	char account[LEN];
	char pass[LEN];
	char nick_name[LEN];
	int mark;
	char str_mark;

	while(1){
		printf("\nNhap ten tai khoan: ");
		strcpy(account,"");
		fgets(account,LEN,stdin);
		account[strlen(account)-1]='\0';
		if(check_xau(account) == 0 || check_input(account) == 0){
			printf("\nMoi nhap lai!!");
		}else break;
	}
	while(1){
		printf("Nhap mat khau: ");
		strcpy(pass,"");
		fgets(pass,LEN,stdin);
		pass[strlen(pass)-1]='\0';
		if(check_xau(pass) == 0 || check_input(pass) == 0){
			printf("\nMoi nhap lai!!\n");
		}else break;
	}
	while(1){
		printf("Nhap nick name: ");
		strcpy(nick_name,"");
		fgets(nick_name,LEN,stdin);
		nick_name[strlen(nick_name)-1]='\0';
		if(check_xau(nick_name) == 0 || check_input(nick_name) == 0){
			printf("\nMoi nhap lai!!\n");
		}else break;
		
	}
	creat_mesg(0,partner,account,pass,nick_name,mesg);
	send(sockfd, mesg,strlen(mesg), 0);
	strcpy(mesg,"");
	recv(sockfd, mesg, LEN, 0);
	mark= check_mark(mesg);
	if(mark == 1) {
		printf("\nDang ki thanh cong");
		return 1;}
	else {
		printf("\nTai khoan da ton tai!!");
		return 0;}
}
Пример #5
0
show_students( struct students *person, int records )
{
    int i,num;
    puts("1-show people with height,weight/2-show people with other characteristics");
    num=atoi(check_input());
    if(num==1)
    {
        for(i=0;i<records;i++)
        {
            if(person[i].union_num==1)
            {
                printf("\n%s%s%s",person[i].fullname.surname, person[i].fullname.name, person[i].fullname.patronymic);
                printf("\n%dsm %dkg",person[i].characteristics.characteristics_1.height, person[i].characteristics.characteristics_1.weight);
            }
        }
    }
    else if(num==2)
    {
        for(i=0;i<records;i++)
        {
            if(person[i].union_num==2)
            {
                printf("\n%s%s%s",person[i].fullname.surname, person[i].fullname.name, person[i].fullname.patronymic);
                printf("\n%dsm %dkg",person[i].characteristics.characteristics_2.height, person[i].characteristics.characteristics_2.weight);
                printf("\n%dyears \npulse: %d ",person[i].characteristics.characteristics_2.age, person[i].characteristics.characteristics_2.pulse);
            }
        }
    }
}
Пример #6
0
//read input
int line_input(char *line_str)
{

	if (get_buffer(line_str)) {
		return 1;

	} else if (check_input()) {

		read_input();

		if (get_buffer(line_str)) {
			return 1;

		} else if (read_end == LINE_INPUT_MAX_CHAR) {

			memcpy(line_str, buffer, LINE_INPUT_MAX_CHAR - 1);
			line_str[LINE_INPUT_MAX_CHAR - 1] = '\0';
			buffer[0] = buffer[LINE_INPUT_MAX_CHAR - 1];

			read_end = 1;
			return 1;

		} else {
			return 0;
		}

	} else {
		return 0;
	}
}
Пример #7
0
int
main (void)
{
  /* The localeconv replacement breaks printf "%lu" on SunOS 4, so we can't
     print the seed in tests_rand_start().  Nothing random is used in this
     program though, so just use the memory tests alone.  */
  tests_memory_start ();

  {
    mpf_t  f;
    char   buf[128];
    mpf_init (f);
    decimal_point = ",";
    mpf_set_d (f, 1.5);
    gmp_snprintf (buf, sizeof(buf), "%.1Ff", f);
    mpf_clear (f);
    if (strcmp (buf, "1,5") != 0)
      {
        printf ("Test skipped, replacing localeconv/nl_langinfo doesn't work\n");
        goto done;
      }
  }

  check_input ();

 done:
  tests_memory_end ();
  exit (0);
}
Пример #8
0
bool GameScreen::run()
{
	running = true;
	Island input_islands[NUM_PLAYERS][MAX_ISLANDS][2];
	//draw_initial(); TODO:GUI
	Team winning_team = NEUTRAL;
	while(running)
	{
		increase_islands();
		for(int player =0; player <= NUM_PLAYERS; player++)
		{
			check_input(input_islands[player], player);
			launch_squadrons(input_islands[player], player);
		}
		check_collisions();
		check_landings();
		winning_team = check_winning_team();
		if(winning_team != NEUTRAL)
		{
			running = false;
		}
		//redraw() TODO:GUI
	}
	return true;
}
Пример #9
0
static void preview_slide()
/*****************************************************************************
 * Display the cel moving across the screen with current slide settings
 * until right click or key is hit.
 ****************************************************************************/
{
int i;
Rcel *cel = cs.ifi.cel;
Boolean abortable = FALSE;

hide_mouse();
sl_ox = cel->x;
sl_oy = cel->y;
for (;;)
	{
	for (i=0; i<cs.slide_frames; i++)
		{
		slide_seek(i,&abortable);
		check_input(ANY_INPUT);
		if(JSTHIT(KEYHIT|MBRIGHT))
			goto OUT;
		wait_a_jiffy(1);
		}
	}
OUT:
cel->x = sl_ox;
cel->y = sl_oy;
conv_see_cel(cel);
show_mouse();
}
Пример #10
0
const saladstate_t parse_stats_options(int argc, char* argv[], config_t* const config)
{
	assert(argv != NULL);
	assert(config != NULL);

	int option;
	while ((option = getopt_long(argc, argv, STATS_OPTION_STR, stats_longopts, NULL)) != -1)
	{
		switch (option)
		{
		case 'b':
			config->input = optarg;
			break;

		case '?':
		case 'h':
			return SALAD_HELP_STATS;

		default:
			// In order to catch program argument that correspond to
			// features that were excluded at compile time.
			fprintf(stderr, "invalid option -- '%c'\n", option);
			return SALAD_HELP_STATS;
		}
	}

	if (check_input(config, TRUE, FALSE) == EXIT_FAILURE)
	{
		return SALAD_EXIT;
	}
	config->bloom = config->input;
	return SALAD_RUN;
}
Пример #11
0
static int	loop(t_env *tenv)
{
	char	*input;
	char	**args;
	int		done;

	done = 0;
	put_prompt(tenv);
	input = read_line(0);
	if (input == NULL)
		return (0);
	if (check_input(input) == 1)
	{
		if (has_cmd_splitter(input) == 1)
		{
			if (only_colon(input) == 0)
				done = handle_multi_command(input, tenv);
		}
		else
		{
			args = msh_sort_quote(input);
			done = msh_handle_input(args, tenv);
			ft_starfree(args);
		}
		ft_strdel(&input);
	}
	return (done);
}
Пример #12
0
/* Boucle principale du jeu */
int	game_loop(char board[3][3])
{
  int	win;
  int	turn;
  int	error;
  int	player;
  char	input[64];
  int	insert_nb;

  win = -1;
  turn = 0;
  error = -42;
  while (win == -1)
    {
      player = turn % 2;
      system("clear");
      display_board(board);
      display_error(error);
      printf("Player %d enter the case number where to put an %c : ", player + 1, player == 0 ? 'X' : 'O');
      scanf("%s", input);
      error = check_input(board, input);
      if (error == -42)
	{
	  insert_nb = input[0] - '1';
	  board[insert_nb / 3][insert_nb % 3] = player;
	  win = check_winner(board, player);
	  if (win >= 0)
	    return (player);
	  else if (turn >= 8)
	    return (2);
	  turn++;
	}
    }
  return (0);
}
Пример #13
0
static t_bool	add_bit(pid_t pid, t_bool bit)
{
	t_stock	*stock;
	t_bit	*bits;
	int		idx;

	stock = gimme_stock(pid);
	idx = 1;
	if (!stock->bit)
	{
		stock->bit = (t_bit*)safe_malloc(sizeof(t_bit));
		stock->bit->bit = bit;
		stock->bit->idx = 0;
		return (TRUE);
	}
	bits = stock->bit;
	while (bits->next)
	{
		idx++;
		bits = bits->next;
	}
	bits->next = (t_bit*)safe_malloc(sizeof(t_bit));
	bits->next->bit = bit;
	bits->next->idx = idx;
	return (check_input(stock->bit, stock));
}
Пример #14
0
long cb_passthrough_resampler_input(cubeb_stream * /*stm*/, void * /*user_ptr*/,
                                    const void * input_buffer,
                                    void * output_buffer, long frame_count)
{
  check_input(input_buffer, output_buffer, frame_count);
  return frame_count;
}
Пример #15
0
int main(int argc, char *argv[])
{
    if(argc>1)
    {
        if(strcmp(argv[1],"-h"))
        {
            show_help();
        }
    }
    struct tree *root=NULL;
    while(1)
    {
        view_menu();
        int number=atoi(check_input());
        if(number==5)
            break;
        switch(number)
        {
            case 1: root=create_root(root); break;
            case 2: add(root); break;
            case 3: show(root); break;
            case 4: enter_level(root); break;
            default : puts("unknown command, try again"); break;
        }

    }
    return 0;
}
Пример #16
0
/*
 * Handle sysfs input to control dedup actions
 */
static ssize_t stats_store(struct kobject *kobj, struct kobj_attribute *attr,
						   const char *buf, size_t count)
{
	long result;
	result = check_input(buf);

	if (result > 0) {
		// Turn dedup ON
		collect_stats = DEDUP_ON;
		blocks_count = (result > BLOCKS_MAX_COUNT) ? BLOCKS_MAX_COUNT : result;
		printk(KERN_ERR "\n---------------\n-     On     -\n- blocks_count = %lu -\n---------------\n", blocks_count);
		duplicatedBlocks = 0;
		if (dedup_calc()) {
			printk(KERN_ERR "calc dedup failed...\n");
		}
	}
	else if (result == 0) {
		// Turn dedup OFF
		printk(KERN_ERR "\n-------\n- Off -\n-------\n");
		collect_stats = DEDUP_ON;
	}
	else if (result == -1) {
		// Some parameter was changed
		printk(KERN_ERR "parameter saved.\n");
	}
	else {
		printk(KERN_ERR "invalid input :(\n");
	}

    return count;
}
Пример #17
0
static void
fbrowse(Flicmenu *m)
{
    int mx,my,mix;
    long dtime;

    dtime = get80hz() + 30;
    which_browse();
    mx = elx;
    my = ely;
    mix = elix;
    bro_frame(mx,my,sred);
    feel_1_browse(list_el(wild_lst, elix+bscroller.top_name));
    bredraw_cpic();
    while (dtime > get80hz())
    {
        check_input();
        which_browse();
        if (elix != mix)
            break;
        if (PJSTDN)
        {
            browse_action();
            if (vs.browse_action == 0) /* short cut to avoid redraw if load */
                return;
        }
    }
    bro_frame(mx,my,swhite);
}
Пример #18
0
void sms_command_r(){
		char a[1];
		unsigned int i;
		str_add_str(output_sms_message,sizeof(output_sms_message),(get_guard_st() ? "na ohrane" : "snqt s ohranQ"),0);
		str_add_str(output_sms_message,sizeof(output_sms_message),"\n",0);
		str_add_str(output_sms_message,sizeof(output_sms_message),"vh:",0);
		for (i = 1;i<6;i++) {
			a[0] = (('-' - (check_input(i)*2)));
			str_add_str(output_sms_message,sizeof(output_sms_message),a,1);
		}
		str_add_str(output_sms_message,sizeof(output_sms_message),"\n",0);
		str_add_str(output_sms_message,sizeof(output_sms_message),"vQh:",0);
		for (i = 1;i<6;i++) {
		//	a[0] = ('1' - (GPIO_READ((outputs_port[(i-1)]),(output[i-1].pin))*2));
			str_add_str(output_sms_message,sizeof(output_sms_message),a,1);
		}
		str_add_str(output_sms_message,sizeof(output_sms_message),"\n",0);
		str_add_str(output_sms_message,sizeof(output_sms_message),"temp:",0);
		for (i = 0;i < get_DS18x20_count();i++){
			int16_t tp = get_last_temp_DS18x20_by_number(i);
			if (tp == ONE_WIRE_CONVERSION_ERROR) str_add_str(output_sms_message,sizeof(output_sms_message),"?",0);
			else str_add_num(output_sms_message,tp);
			str_add_str(output_sms_message,sizeof(output_sms_message),";",0);
		}
		str_add_str(output_sms_message,sizeof(output_sms_message),"\n",0);
		if (get_powered() == POWERED_220V) str_add_str(output_sms_message,sizeof(output_sms_message),"220v",0);
		else str_add_str(output_sms_message,sizeof(output_sms_message),"akkum!",0);
		send_sms_message_for_all(output_sms_message,SMS_FUNCTION_SERVICE);
}
Пример #19
0
  int eigen_decomposition(int n, double* X, double *eigvec, double *eigval) {
    /*
      This function calculates the eigenvalues and eigenvectors of
      the n*n symmetric matrix X.
      The matrices have to be in Fortran vector format.
      The eigenvectors will be put columnwise in the n*n matrix eigvec,
      where the corresponding eigenvalues will be put in the vector
      eigval (length n of course). Only the lower triangle of the matrix
      X is used. The content of X is not changed.
      This function first queries the Lapack routines for optimal workspace
      sizes. These memoryblocks are then allocated and the decomposition is
      calculated using the Lapack function "dsyevr". The allocated memory
      is then freed.
    */

    double *WORK, *Xc;
    int *ISUPPZ, *IWORK;
    int numeig, info, sizeWORK, sizeIWORK;

    if (check_input(X, eigvec, "eigen_decomposition")) return 1;

    /* Use a copy of X so we don't need to change its value or use its memoryblock */
    Xc=(double*) malloc(n*n*sizeof(double));

    /* The support of the eigenvectors. We will not use this but the routine needs it */
    ISUPPZ = (int*) malloc (2*n*sizeof(int));

    /* Allocate temporarily minimally allowed size for workspace arrays */
    WORK = (double*) malloc (26*n*sizeof(double));
    IWORK = (int*) malloc (10*n*sizeof(int));

    /* Check for NULL-pointers. */
    if ((Xc==NULL)||(ISUPPZ==NULL)||(WORK==NULL)||(IWORK==NULL)) {
      printf("malloc failed in eigen_decomposition\n");
      return 2;
    }

    vector_copy(n*n, X, Xc);

    /* Query the Lapack routine for optimal sizes for workspace arrays */
    info=dsyevr ('V', 'A', 'L', n, Xc, n, 0, 0, 0, 0, dlamch('S'), &numeig, eigval, eigvec, n, ISUPPZ, WORK, -1, IWORK, -1);
    sizeWORK = (int)WORK[0];
    sizeIWORK = IWORK[0];

    /* Free previous allocation and reallocate preferable workspaces, Check result */
    free(WORK);free(IWORK);
    WORK = (double*) malloc (sizeWORK*sizeof(double));
    IWORK = (int*) malloc (sizeIWORK*sizeof(int));
    if ((WORK==NULL)||(IWORK==NULL)) {
      printf("malloc failed in eigen_decomposition\n");
      return 2;
    }

    /* Now calculate the eigenvalues and vectors using optimal workspaces */
    info=dsyevr ('V', 'A', 'L', n, Xc, n, 0, 0, 0, 0, dlamch('S'), &numeig, eigval, eigvec, n, ISUPPZ, WORK, sizeWORK, IWORK, sizeIWORK);

    /* Cleanup and exit */
    free(WORK); free(IWORK); free(ISUPPZ); free(Xc);
    return info;
  }
Пример #20
0
int main(void)
{
    int offset, matches;
    char *filePath = "source.sub";
    char *destPath = "fixed.sub";
    
    printf("offset --> ");
    matches = scanf("%d", &offset);
    check_input(matches);
    
    FILE *file = fopen(filePath, "r");
    FILE *dest = fopen(destPath, "w");
    
    if (NULL == dest || NULL == file) 
    {
        kill(NULL);
    }
    
    char buffer[BUFFER_SIZE];
    char *timeEnd;
    char *timeStart;
    
    while ((0 == feof(file)) && (0 == ferror(file)) && (0 == ferror(dest)))
    {
        size_t readBytes = fread(buffer, 1, BUFFER_SIZE, file);
        char *substr;
        substr = strstr(buffer, "-->");
        while (NULL != substr)
        {
            int check = check_buffer(buffer, substr, readBytes);
            
            if (1 == check) 
            {
                timeEnd = substr + OFFSET_TO_ENDTIME;
                timeStart = substr - TIME_SIZE -1;
                char startTime[TIME_SIZE + 1];
                strncpy(startTime, timeStart, TIME_SIZE);
                startTime[TIME_SIZE] = '\0';
                char endTime[TIME_SIZE +1];
                strncpy(endTime, timeEnd, TIME_SIZE);
                endTime[TIME_SIZE] = '\0';

                change_time(startTime, offset);
                strncpy(timeStart, startTime, TIME_SIZE);
                change_time(endTime, offset);
                strncpy(timeEnd, endTime, TIME_SIZE);
            } 
            
            substr = strstr(timeEnd, "-->");
        }
        
        fwrite(buffer, 1, readBytes, dest);
    }
    
    fclose(file);
    fclose(dest);

    return 0;
}
Пример #21
0
  int matrix_square_root_n(int n, double *X, double *I, double *Y) {

    /*
      This function calculates one of the square roots of the matrix X and stores it in Y:
      X = sqrt(Y);
      X needs to be a symmetric positive definite matrix of dimension n*n in Fortran vector
      format. Y is of course a vector of similar size, and will contain the result on exit.
      Y will be used as a workspace variable in the meantime.
      The variable I is a vector of length n containing +1 and -1 elements. It can be used
      to select one of the 2^n different square roots of X
      This function first calculates the eigenvalue decomposition of X: X = U*D*U^T
      A new matrix F is then calculated with on the diagonal the square roots of D, with
      signs taken from I.
      The square root is then obtained by calculating U*F*U^T
    */

    if (check_input(X, Y, "matrix_square_root_n")) return 1;

    double *eigval, *eigvec, *temp;
    int info = 0, i, j;

    /* Memory allocation */
    eigval=(double*) malloc(n*sizeof(double));
    eigvec=(double*) malloc(n*n*sizeof(double));
    temp=(double*) malloc(n*n*sizeof(double));
    if ((eigval==NULL)||(eigvec==NULL)||(temp==NULL)) {
      printf("malloc failed in matrix_square_root_n\n");
      return 2;
    }

    /* Eigen decomposition */
    info=eigen_decomposition(n, X, eigvec, eigval);
    if (info != 0) return info;

    /* Check for positive definitiveness*/
    for (i=0; i<n; i++) if (eigval[i]<0) {
	fprintf(stderr, "In matrix_square_root_n: Matrix is not positive definite.\n");
	return 1;
      }

    /* Build square rooted diagonal matrix, with sign signature I */
    for (i=0; i<n; i++) for (j=0; j<n; j++) Y[i*n+j] = 0.0;
    for (i=0; i<n; i++) Y[i*n+i] = I[i]*sqrt(eigval[i]);

    /* Multiply the eigenvectors with this diagonal matrix Y. Store back in Y */
    matrix_matrix_mult(n, n, n, 1.0, 0, eigvec, Y, temp);
    vector_copy(n*n, temp, Y);

    /* Transpose eigenvectors. Store in temp */
    matrix_transpose(n, n, eigvec, temp);

    /* Multiply Y with this temp. Store in eigvec which is no longer required. Copy to Y */
    matrix_matrix_mult(n, n, n, 1.0, 0, Y, temp, eigvec);
    vector_copy(n*n, eigvec, Y);

    /* Cleanup and exit */
    free(eigvec); free(eigval); free(temp);
    return info;
  }
Пример #22
0
 void vector_add(int n, double a, double *X, double *Y) {
   /*
     Calculates Y = a*X + Y
     X and Y are vectors of length n
   */
   check_input(X, Y, "vector_add");
   cblas_daxpy(n, a, X, 1, Y, 1);
 }
Пример #23
0
 void matrix_vector_mult(int m, int n, double a, double b, double *A, double *x, double *y) {
   /*
     Calculates y = a*A*x + b*y
     A is m*n matrix in Fortran vector format, so x and y need to have length m
   */
   check_input(x, y, "matrix_vector_mult");
   cblas_dgemv (CblasColMajor, CblasNoTrans, m, n, a, A, m, x, 1, b, y, 1);
 }
Пример #24
0
void input(struct students *person, int records)
{
    char *string;
    do{
           string=(char*)calloc(20,sizeof(char));
    }while(!string);
    int number=0,num;
    puts("enter surname ");
    string = check_input();
    strcpy(person[records].fullname.surname, delete_space(string));
    puts("enter name ");
    string = check_input();
    strcpy(person[records].fullname.name, delete_space(string));
    puts("enter patronymic ");
    string = check_input();
    strcpy(person[records].fullname.patronymic, delete_space(string));
    puts("1-height,weight 2-height,weight,other characteristics");
    num=atoi(check_input());
    if(num==1)
    {
        person[records].union_num=1;
        puts("enter height");
        number=atoi(check_input());
        person[records].characteristics.characteristics_1.height=number;
        puts("enter weight");
        number=atoi(check_input());
        person[records].characteristics.characteristics_1.weight=number;
    }
    else
    {
        person[records].union_num=2;
        puts("enter height");
        number=atoi(check_input());
        person[records].characteristics.characteristics_2.height=number;
        puts("enter weight");
        number=atoi(check_input());
        person[records].characteristics.characteristics_2.weight=number;
        puts("enter age");
        number=atoi(check_input());
        person[records].characteristics.characteristics_2.age=number;
        puts("enter pulse");
        number=atoi(check_input());
        person[records].characteristics.characteristics_2.pulse=number;
    }
}
Пример #25
0
 void matrix_transpose(int m, int n, double *X, double *Y) {
   /*
     Transposes an m*n matrix: Y = X^T
     Matrix can be in either C or Fortran vector format
   */
   check_input(X,Y, "matrix_transpose");
   int i,j;
   for (i=0; i<m; i++) for (j=0; j<n; j++) Y[n*i+j] = X[i+m*j];
 }
Пример #26
0
 void fvec2cvec(int m, int n, double *fvec, double* cvec) {
   /*
     Turn matrix in Fortran vector format into matrix in C vector format
     Matrix has dimension m*n
   */
   int i,j;
   check_input(cvec, fvec, "fvec2cvec");
   for (i=0; i<m; i++) for (j=0; j<n; j++) cvec[n*i+j] = fvec[i+m*j];
 }
Пример #27
0
/**
 * \brief The main function.
 *
 * The main loop is executed here.
 */
void MainLoop::run() {

  // Main loop.
  uint32_t last_frame_date = System::get_real_time();
  uint32_t lag = 0;  // Lose time of the simulation to catch up.
  uint32_t time_dropped = 0;  // Time that won't be caught up.

  // The main loop basically repeats
  // check_input(), update(), draw() and sleep().
  // Each call to update() makes the simulated time advance one fixed step.
  while (!is_exiting()) {

    // Measure the time of the last iteration.
    uint32_t now = System::get_real_time() - time_dropped;
    uint32_t last_frame_duration = now - last_frame_date;
    last_frame_date = now;
    lag += last_frame_duration;
    // At this point, lag represents how much late the simulated time with
    // compared to the real time.
 
    if (lag >= 200) {
      // Huge lag: don't try to catch up.
      // Maybe we have just made a one-time heavy operation like loading a
      // big file, or the process was just unsuspended.
      // Let's fake the real time instead.
      time_dropped += lag - System::timestep;
      lag = System::timestep;
      last_frame_date = System::get_real_time() - time_dropped;
    }

    // 1. Detect and handle input events.
    check_input();

    // 2. Update the world once, or several times (skipping some draws)
    // to catch up if the system is slow.
    int num_updates = 0;
    while (lag >= System::timestep
        && num_updates < 10  // To draw sometimes anyway on very slow systems.
        && !is_exiting()) {
      update();
      lag -= System::timestep;
      ++num_updates;
    }

    // 3. Redraw the screen.
    if (num_updates > 0) {
      draw();
    }

    // 4. Sleep if we have time, to save CPU and GPU cycles.
    last_frame_duration = (System::get_real_time() - time_dropped) - last_frame_date;
    if (last_frame_duration < System::timestep) {
      System::sleep(System::timestep - last_frame_duration);
    }
  }
}
Пример #28
0
int login(int sockfd){
	char mesg[LEN];
	char partner[]="0";
	char pass[LEN];
	char account[LEN];
	char nick_name[]="0";
	int mark,n;
	char str_mark;

	
	while(1){
		printf("\nNhap ten tai khoan: ");
		strcpy(account,"");
		fgets(account,LEN,stdin);
		account[strlen(account)-1]='\0';
		if(check_xau(account) == 0 || check_input(account) == 0){
			printf("\nMoi nhap lai!!");
		}else break;
	}

	while(1){
		printf("Nhap mat khau: ");
		strcpy(pass,"");
		fgets(pass,LEN,stdin);
		pass[strlen(pass)-1]='\0';
		if(check_xau(pass) == 0 || check_input(pass) == 0){
			printf("\nMoi nhap lai!!\n");
		}else break;
	}
	strcpy(mesg,"");
	creat_mesg(1,partner,account,pass,nick_name,mesg);
	send(sockfd, mesg,strlen(mesg), 0);
	strcpy(mesg,"");
	n=recv(sockfd, mesg, LEN, 0);

	mark= check_mark(mesg);
	if(mark == 1) {
		printf("\nDang nhap thanh cong");
		return 1;}
	else {
		printf("\nTai khoan hoac mat khau khong dung!!");
		return 0;}
}
Пример #29
0
int main ( const int argc, const char** argv )
{
	check_input  ( argc       );
	CTask my_task( argc, argv );

	my_task.readData   ( argv[INPUT_FILE_ARG ] );
	my_task.doOperation( argv[OUTPUT_FILE_ARG] );

	return 0;
}
Пример #30
0
int main(int argc, char** argv)
{
    int ret = EXIT_SUCCESS;

    /* Initialize param struct to zero */
    memset(&P, 0, sizeof(P));

    if (!parse_input(argc, argv)) {
        return EXIT_FAILURE;
    }

    /* Initialize parameters corresponding to YUV-format */
    setup_param();

    if (!sdl_init()) {
        return EXIT_FAILURE;
    }

    if (!open_input()) {
        return EXIT_FAILURE;
    }

    if (!allocate_memory()) {
        ret = EXIT_FAILURE;
        goto cleanup;
    }

    /* Lets do some basic consistency check on input */
    check_input();

    /* send event to display first frame */
    event.type = SDL_KEYDOWN;
    event.key.keysym.sym = SDLK_RIGHT;
    SDL_PushEvent(&event);

    /* while true */
    event_loop();

cleanup:
    destroy_message_queue();
    SDL_FreeYUVOverlay(my_overlay);
    free(P.raw);
    free(P.y_data);
    free(P.cb_data);
    free(P.cr_data);
    if (fd) {
        fclose(fd);
    }
    if (P.fd2) {
        fclose(P.fd2);
    }

    return ret;
}