Exemple #1
0
main()
{
	char *data;
	int len;
	int ret;
	int i=0;
	int flag=0;
	int digit=0;
	char **str;	

	do
	{
		printf("input length of string\n");
		scanf("%d",&len);
	}while(len<=0);
	getchar();

/*分配字符串空间*/
	ret = dynamic_create(&data,(len+1)*sizeof(char));
	if(ret!=OK)
	{
		printf("分配空间失败\n");
		return ER;
	}

/*输入字符串*/
	ret = input_str(data,len);
	if(ER==ret)
	{
		printf("赋值失败\n");
		return ER;
	}
	printf("string=%s\n",data);

/*计算数字串的个数*/	
	ret = num_count(data,&digit);
	if(ER==ret)
	{
		return ER;
	}
	printf("digit=%d\n",digit);
	
/*开辟一个指针数组*/
	ret = dynamic_create((void**)&str,digit*sizeof(char*));
	if(ER==ret)
	{
		return ER;
	}
printf("digit=%d\n",digit);
	printf("开辟指针数组成功\n");


	 str_trans(data,str);//将字符串中的数字串转置存储
	
	for(i=0;i<digit;i++)
	{
		printf("str%d=%s\n",i,*(str+i));
	}

}
Exemple #2
0
enum CID input() {    
    char * cmd = input_str();       
    for (int i=0; i<CMD_COUNT; i++) {
       if (strcmp(commands[i].command, cmd)==0) 
           return(commands[i].cid);
    }
    return NOPE;
 }
Exemple #3
0
int main(int argc, char* argv[])
{

	std::string word;
	std::string input;

	std::getline(std::cin, input);
	std::istringstream input_str(input);
	while (input_str >> word) {
		std::cout << word << std::endl;
	}

	return 0;
}
int Retry(){
	char repeater[4];
	while(1){
		printf("Retry Now? [yes/no] :");
		input_str(&repeater[0], sizeof(repeater));
		if ('y' == repeater[0] || 'Y' == repeater[0]){
			return 0;
		}
		if ('n' == repeater[0] || 'N' == repeater[0]){
			return 1;
		}
		printf("Input error. ");
	}
}
Exemple #5
0
void lancia_shell(SocketUDP *udp) {
	char *lettura;
	Address addr(BROADCAST_IP, broadcast_port);
	
	while(strcmp(lettura = input_str(), EXIT_CMD)) {
		
		udp->invia(addr, lettura);
		
		free(lettura);
	}
	
	free(lettura);
	
}
static int BoostBase64Test()
{

	std::string input_str("{\"digit\":0,\"pcver\":0,\"protocol\":30001}\n");
	std::string base64_str, output_str;

	std::cout<<"origin text: \n"<<input_str<<std::endl;

	BoostBase64Encode(input_str, base64_str);
	std::cout<<"encode: \n"<<base64_str<<std::endl;

	BoostBase64Decode(base64_str, output_str);
	std::cout<<"decode: \n"<<output_str<<std::endl;

	return 0;
}
Exemple #7
0
//动态生成4x5数组
//找出每行最大的地址保存到数组指针
int main(int argc, const char *argv[])
{
	//一个指针指向5个数组
	int (*arr)[5] = NULL;
	int *max_arrs[4] = {NULL, NULL, NULL, NULL};
	input_str(arr, ROW, COL);

	//find_max(max_arr, arr, ROW);

	int i,j;
	for (i = 0; i < ; i++) {

	}


	return 0;
}
Exemple #8
0
int XtfsUtilServer::write(uid_t uid,
                          gid_t gid,
                          const xtreemfs::pbrpc::UserCredentials& uc,
                          const std::string& path,
                          const char *buf,
                          size_t size) {
  XCtlFile* file = FindFile(uid, gid, path, true);
  assert(file);
  if (file->in_use()) {
    return -1 * EAGAIN;
  }
  file->set_in_use(true);
  string input_str(buf, size);
  ParseAndExecute(uc, input_str, file);
  file->set_in_use(false);
  return size;
}
Exemple #9
0
inline std::string HttpHandler::trimAndLower(const char* input)
{
    if (input == nullptr)
    {
        return std::string();
    }

    std::string input_str(input);

    auto wsfront = std::find_if_not(input_str.begin(), input_str.end(), [](int c) {
        return std::isspace(c);
    });
    auto wsback = std::find_if_not(input_str.rbegin(), input_str.rend(), [](int c) {
        return std::isspace(c);
    }).base();

    return (wsback <= wsfront ? std::string() : std::string(wsfront, wsback));
}
Exemple #10
0
int main(void)
{
	char *arr[2] = {NULL, NULL};	
	char *max = NULL;
	int i;
	
	input_str(arr, 2);

	puts(arr[0]);
	puts(arr[1]);

	max_str(arr, 2, &max);


	puts(max);

	free(arr[0]);
	free(arr[1]);

	free(max);
	return 0;
}
Exemple #11
0
// seg001:09D7
void __pascal far end_sequence() {
	peel_type* peel;
	short bgcolor;
	short color;
	rect_type rect;
	short hof_index;
	short i;
	color = 0;
	bgcolor = 15;
	load_intro(1, &end_sequence_anim, 1);
	clear_screen_and_sounds();
	load_opt_sounds(sound_56_ending_music, sound_56_ending_music); // winning theme
	play_sound_from_buffer(sound_pointers[sound_56_ending_music]); // winning theme
	if(offscreen_surface) free_surface(offscreen_surface); // missing in original
	offscreen_surface = make_offscreen_buffer(&screen_rect);
	load_title_images(0);
	current_target_surface = offscreen_surface;
	draw_image_2(0 /*story frame*/, chtab_title40, 0, 0, 0);
	draw_image_2(3 /*The tyrant Jaffar*/, chtab_title40, 24, 25, get_text_color(15, color_15_brightwhite, 0x800));
	fade_in_2(offscreen_surface, 0x800);
	pop_wait(timer_0, 900);
	start_timer(timer_0, 240);
	draw_image_2(0 /*main title image*/, chtab_title50, 0, 0, 0);
	transition_ltr();
	do_wait(timer_0);
	for (hof_index = 0; hof_index < hof_count; ++hof_index) {
		if (hof[hof_index].min < rem_min ||
			(hof[hof_index].min == rem_min && hof[hof_index].tick < rem_tick)
		) break;
	}
	if (hof_index < MAX_HOF_COUNT && hof_index <= hof_count) {
		fade_out_2(0x1000);
		for (i = 5; hof_index + 1 <= i; --i) {
			hof[i] = hof[i - 1];
		}
		hof[i].name[0] = 0;
		hof[i].min = rem_min;
		hof[i].tick = rem_tick;
		if (hof_count < MAX_HOF_COUNT) {
			++hof_count;
		}
		draw_image_2(0 /*story frame*/, chtab_title40, 0, 0, 0);
		draw_image_2(3 /*Prince Of Persia*/, chtab_title50, 24, 24, blitters_10h_transp);
		show_hof();
		offset4_rect_add(&rect, &hof_rects[hof_index], -4, -1, -40, -1);
		peel = read_peel_from_screen(&rect);
		if (graphics_mode == gmMcgaVga) {
			color = 0xBE;
			bgcolor = 0xB7;
		}
		draw_rect(&rect, bgcolor);
		fade_in_2(offscreen_surface, 0x1800);
		current_target_surface = onscreen_surface_;
		while(input_str(&rect, hof[hof_index].name, 24, "", 0, 4, color, bgcolor) <= 0);
		restore_peel(peel);
		show_hof_text(&hof_rects[hof_index], -1, 0, hof[hof_index].name);
		hof_write();
		pop_wait(timer_0, 120);
		current_target_surface = offscreen_surface;
		draw_image_2(0 /*main title image*/, chtab_title50, 0, 0, blitters_0_no_transp);
		transition_ltr();
	}
	while (check_sound_playing() && !key_test_quit()) idle();
	fade_out_2(0x1000);
	start_level = 0;
	start_game();
}
int main(){
	int i;
	int play;
	int anser[4];
	char input[6];
	int hit = 0, blow = 0;

	do{
		srand ((unsigned) time (NULL));

		printf("\n------------- Hit and Blow -------------\n\n");

		make4number(&anser[0]);

		for(play = 0 ; play < 10 ; ++play){
			int Flag = 0;

			printf("%d", play + 1);
			switch(play){
				case 0:
					printf("st "); break;
				case 1:
				case 2:
					printf("nd "); break;
				default:
					printf("th ");
			}
			printf("try.\n");

			do{
				printf("Number:");
				input_str(&input[0], sizeof(input));
				if(0 == checknumber(input)){
					Flag = 1;
				}else if (1 == checknumber(input)){
					printf("Error : number of digits is not correct.\n");
				}else if(2 == checknumber(input)){
					printf("Error: contains non-numeric.\n");
				}else if (3 == checknumber(input)){
					printf("Error: contains the same number.\n");
				}
			}while (Flag == 0);
			judgeHB(anser, input, &hit, &blow);
			if(4 == hit){
				printf("congratulations!\nIt is a success in the %d", play);
				switch(play){
					case 1:
						printf("st."); break;
					case 2:
					case 3:
						printf("nd."); break;
					default:
						printf("th.");
				}
				break;
			}else{
				printHB(hit, blow);
			}
			hit = 0;
			blow = 0;
		}
		if (play == 10){
			printf("That's too bad.\n");
		for(i = 0 ; i < 4 ; ++i){
			printf("%d", anser[i]);
		}
		}
		puts ("");
	}while(0 ==Retry());
	return 0;
}
Exemple #13
0
void process_commands(enum CID cid) {
    cursor_t old_c;
    char * dbName;
    switch (cid) {
        case NOPE:
              puts("-- команда не распознана --");
              break;
        case SET_NAME:              
              if (db_ship()) {
                printf("Имя>");
                strncpy(db_ship()->name,input_str(),64);
                show();
          }
            break;
        case SET_YEAR:
              if (db_ship()) {
                printf("Год>");
                db_ship()->year = strtoul( input_str(),NULL, 10);
                show();
          }
            break;
        case COPY:
             db_copy();
             break;
        case PASTE:
             db_paste();
             show();
             break;
        case ALL:
             old_c = db_get_cursor();
             db_first();             
             while (db_get_cursor() != db_get_end()) {
                 db_load();
                 if (!db_is_deleted())
                    show();
                 db_next();
             }
             db_set_cursor(old_c);
             db_load();
             break;
        case REFRESH:
             db_load();
        case SHOW:
            show();
            break;

        case NEW:
             db_new();
             show();            
             break;
        case REMOVE:
                db_delete();        
                break;
        case SAVE:
              db_save();
             break; 

        case HELP:
              show_help();
              break;
        case OPEN:        
                printf("Файл>");
                dbName = input_str();
                db_open( strlen(dbName) == 0 ?  "ships.db" : dbName);
                break;
        case CLOSE:
                db_close();
                break;
        case  FIRST:
                first:
                db_first();
                while (db_get_cursor() != db_get_end()) {                   
                   db_load();
                   if (!db_is_deleted()) {
                       show();
                       return;
                   }                   
                   db_next();
                }
                puts("-- в базе нет записей. --");                
                break;
        case  NEXT: 
                db_next();
                while (db_get_cursor() != db_get_end()) {
                    db_load();
                    if (!db_is_deleted()) {
                       show();
                       return;
                   }
                   db_next();
                }
                puts("-- больше записей нет. перемотка в начало. --");
                goto first;                 
        case PREV:              
                while (db_get_cursor() != db_get_begin()) {
                   db_prev();
                   db_load();
                   if (!db_is_deleted()) {
                       show();
                       return;
                   }
                }
                puts("-- первая запись --");                
                goto first;             
                break;
        default:
            puts("== команда не обработана ==");

    }    
}
Exemple #14
0
int main(int argc, char *argv[])
{
	time_t startTime;
	bool started_flag = false;
	bool drinks_disabled_flag = false;
	bool metric_flag = false;
	
	//This is the variable that holds the current amount of caffeine
	//so basicly the whole program is centred around changing this
	//variable. Change with caution!
	double caffeineAmount  = 0.0;
	double caffeineTotal   = 0.0;
	double addCaffeine     = 0.0;
	double amountRemaining = 0.0;
	
	display_heading("Eternal Caffeine v2.0 <copyleft. 2015-2016>\n");
	
	if(argc > 1){ //if any arguments are give at all
		printf("I don't know what `%s' is but here is the help menu.\n", argv[1]);
		usage();
		exit(EXIT_SUCCESS);
	}
	
	puts("Enter help for usage.\n\n");
	
	
	
	
	FILE *drinkfile = fopen(DRINK_PATH_CURRENT, "r");
	
	if(drinkfile == NULL){ //try the install path
		drinkfile = fopen(DRINK_PATH_INSTALL, "r");
	}
	
	const unsigned int DRINK_COUNT = count_lines(drinkfile); //we must count the number of entries so we know how much to allocate
	struct drink drink_table[DRINK_COUNT];
	
	if(DRINK_COUNT == 0 || drinkfile == NULL){
		puts("No drinks found! Disabling drinks feature...");
		drinks_disabled_flag = true;
	} else {
		load_drinks(drinkfile, drink_table, drinks_disabled_flag);
		fclose(drinkfile);
	}
	
	
	
	char command[INPUT_MAX];
	while(IM_ETERNAL){
		printf("command");
		input_str(command);
		
		if( string_compare(command, "help") ){
			
			usage();
		
		} else if ( string_compare(command, "start") || string_compare(command, "update") ){
			
			if(started_flag){
				//do halflife before add new amount
				caffeineAmount = half_life(caffeineAmount,
				                           time_elapsed(startTime),
				                           HALFLIFE_OF_CAFFEINE);
			} else {
				started_flag = true;
			}
			
			startTime      = time(NULL);
			
			//add new amount
			addCaffeine    = update(drink_table, DRINK_COUNT, drinks_disabled_flag, metric_flag);
			caffeineAmount = caffeineAmount + addCaffeine;
			caffeineTotal  = caffeineTotal + addCaffeine;
			
			printf("Caffeine amount is now %.02lfmg\n", caffeineAmount);
			
		} else if( string_compare(command, "report") ){
			
			if(! started_flag ){
				puts("You have not started yet. Enter the start command!!!");
				continue;
			}
			
			amountRemaining = half_life(caffeineAmount,
			                            time_elapsed(startTime),
			                            HALFLIFE_OF_CAFFEINE);
			
			give_report(amountRemaining, caffeineTotal);
		
		} else if( string_compare(command, "quit") ){
			
			putchar('\n');
			exit(EXIT_SUCCESS);
		
		} else if( string_compare(command, "metric") ){
			metric_flag = !metric_flag; //toggle
			
			printf("Metric is now ");
			if(metric_flag){
				printf("on.\n");
			}else{
				printf("off.\n");
			}
			
		} else if( string_compare(command, "wipe") ){
			
			addCaffeine = caffeineAmount = caffeineTotal = 0.0;
			metric_flag = started_flag = false;
			
			puts("All values have been reset.");
			
		} else {
			
			puts("Command unknown. Enter help for usage.");
			continue;
			
		}
		
	}
	
	
	
	return EXIT_SUCCESS;
}