Ejemplo n.º 1
0
/**
 * Prepis programu wordcount z C++ do C zo zadania.
 */
int main(void)
{

	htab_t *t=htab_init(HTAB_SIZE);
	if(!t)
	{
		fprintf(stderr, "[wordcount]\t-htable was not allocated\n");
		return EXIT_FAILURE;
	}
	
	char word[WORD_LIMIT+1]={0};

	
	while(fgetw(word, WORD_LIMIT, stdin)!=EOF)
	{
		if(!htab_lookup(t, word))
		{
			fprintf(stderr, "[wordcount]\t-[htab_lookup] allocation fail\n");
			htab_free(t);
			return EXIT_FAILURE;
		}
	}


	htab_foreach(t, &print_items);
	
	//htab_statistics(t); /// vypis statistiky udajov tabulky
	
	htab_free(t);
	return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
struct htab _new_htab(int n)
{
	struct htab htab;

	htab_init(&htab, n);
	return htab;
}
Ejemplo n.º 3
0
/*
 * Read words from stdin and print number of occurrences
 * @param	argc	number of arguments
 * @param	argv	arguments
 * @return	success code
 *
 */
int main(int argc, char* argv[])
{
	// This size is used, because it is enought for entire book (tested on Alice's Adventures in Wonderland and Pride and Prejudice)
	// and average number is between 0.5-2 - is used more than half and is average not more than 2 items
	htab_t* htab = htab_init(7000);
	htab_listitem* item;
	
	char word[128];
	while(fgetw(word, 127,stdin) != EOF)
	{
		item = htab_lookup(htab,word);
		item->data++;
	}

	htab_foreach(htab, &print_word);
	
	//htab_statistics(htab);

	htab_free(htab);

	return 0;
}
Ejemplo n.º 4
0
// меню работы с пациентами
void pat_menu(hash_tab **pat, node *doc, refferal **ref_head, refferal **ref_tail)
{
	bool end(false); // флаг остановки работы(возврат в главное меню)
	svector_pat search; // вектор найденных данных врачей
	int choice; // выбор критерия
	string answer; // ответ на вопрос д\н

	while(!end) 
	{
		system("cls");
		cout<<"======= Работа с клиентурой =======\n"
			<<" 1. Регистрация нового больного\n"
			<<" 2. Удаление данных о больном\n"
			<<" 3. Список всех больных\n"
			<<" 4. Удаление данных о всех больных\n"
			<<" 5. Поиск\n"
			<<" 0. Назад в меню\n"
			<<"===================================\n"
			<<"\nВведите команду: ";
		choice = input_control(5, 0);
		if ((choice >= 2 && choice <= 5) && !(have_pat(*pat)))
		{
			cout << "\nБД пациентов пуста! Пункты #2 - #5 недоступны.\n";
			system("pause");
			choice = -1;
		}
		switch(choice)
		{
		case 1:
			cout<<" Регистрация больного:\n";
			add_to_tab(*pat, pat_init());
			system("pause");
			break;
		case 2:
			del_pat(*pat, ref_head, ref_tail);
			system("pause");
			break;
		case 3:
			pat_out(*pat);
			system("pause");
			break;
		case 4:
			cout << " Удалить данные о всех больных? \n(Также удалится вся информация о выданных направлениях на прием) д/н ";
			answer_control(answer);
			if (answer[0] == 'д')
			{
				htab_init(*pat);
				del_list(ref_head, ref_tail);
				cout << " Записи удалены.\n";
				system("pause");
			}
			else
			{
				cout << " Записи НЕ удалены.\n";
				system("pause");
			}
			break;
		case 5:
			pat_search_menu(search, *pat, doc, *ref_head);
			system("pause");
			break;
		case 0:
			end = true;
			break;
		default:
			break;
		}
		search.clear();
		search.shrink_to_fit();
	}
}