示例#1
0
int main(int argc, char *argv[]){

	printf("====================== Testing Create BST ====================\n");
	char * businesses_path = "/home/pharaoh/ece264/solutions/ece264/PA10/businesses.tsv";
	char * reviews_path = "/home/pharaoh/ece264/solutions/ece264/PA10/reviews.tsv";
	struct YelpDataBST * bst = NULL;
	bst = create_business_bst(businesses_path, reviews_path);
	printf("%p\n", bst);

	printf("====================== Testing The Search ====================\n");
	get_business_reviews(bst, "Starbucks", NULL, NULL);


	return EXIT_SUCCESS;
}
示例#2
0
int main(int argc, char *argv[]) {

	// Create instance of YelpDataBST
	struct YelpDataBST* bst = create_business_bst(businesses_path, reviews_path);

	char * test0[4] = { "", "Boston Cleaners", "NV", "89135" };
	Search(4, test0, "test0", bst);

	char * test1[4] = { "", "Boston Cleaners", "NV", "" };
	Search(4, test1, "test1", bst);

	char * test2[4] = { "", "Boston Cleaners", "", "" };
	Search(4, test2, "test2", bst);

	char * test3[4] = { "", "Boston Cleaners", "", "89135" };
	Search(4, test3, "test3", bst);

	char * test4[4] = { "", "bOsToN cLeAnErS", "nV", "89135" };
	Search(4, test4, "test4", bst);

	char * test5[4] = { "", "Ruby's Diner", "", "" };
	Search(4, test5, "test5", bst);

	char * test6[4] = { "", "Capriotti's", "", "" };
	Search(4, test6, "test6", bst);

	char * test7[4] = { "", "Subway", "AA", "" };
	Search(4, test7, "test7", bst);

	char * test8[4] = { "", "Subway", "", "00000" };
	Search(4, test8, "test8", bst);

	char * test9[4] = { "", "aaaaaaaaaaa", "", "" };
	Search(4, test9, "test9", bst);

	char * test10[4] = { "", "Simplicity Laser Hair Removal", "", "" };
	Search(4, test10, "test10", bst);

	char * test11[13] = { "", "McDonald's", "", "", "Burger King", "", "", "Wendy's", "", "", "Starbucks", "", "" };
	Search(13, test11, "test11", bst);
	
	// Destroy (free) the BST and 
	destroy_business_bst(bst);

	return EXIT_SUCCESS;
}
示例#3
0
文件: main.c 项目: haynes1/ece264
int main(int argc, char *argv[]){
	int i;

	char businesses_path[] = "/home/pharaoh/ece264/solutions/ece264/PA10/businesses.tsv";
	char reviews_path[] = "/home/pharaoh/ece264/solutions/ece264/PA10/reviews.tsv";

	if(argc == 1) {
		fprintf(stderr, "=================================================Starting Program=============================================\n");
		fprintf(stderr, "Run this program with a 1 as the argument to procede.\nThis will start the building of the BST\n");
		fprintf(stderr, "It will take 1ish min to complete, and will only happen once before multiple searches can be made.\n\n");
		return EXIT_FAILURE;
	}
	if (argc == 2 && strcmp(argv[1], "1") == 0)
	{
		fprintf(stderr, "=================================================Starting Program=============================================\n");
		fprintf(stderr, "Starting to build the BST.\n");
		fprintf(stderr, "This will take approximately 1ish minutes to complete before you will be prompted for multiple searches\n");
	}
	else
	{
		printf("argv[1] must be 1 to continue.\n");
		return EXIT_FAILURE;
	}

	//create the BST
	struct YelpDataBST * bst = NULL;
	int total_businesses = 0;
	bst = create_business_bst(businesses_path, reviews_path, &total_businesses);

	//prompt user, and do the searches
	int continue_searching = 1;
	char * prompt1 = "Name: ";
	char * promptstate = "State: ";
	char * promptzip = "Zip: ";
	char * promptwords ="Words: ";
	int max_line_length = 2000;
	char * line = malloc(max_line_length * sizeof(char));
	while(continue_searching == 1)
	{
		printf("++++++\nStarting a Search\nEnter -1 at any time to exit\n+++++\n");
		char * name = malloc(MAXNAME * sizeof(char));
		char * state = malloc(MAXSTATE * sizeof(char));
		char * zip = malloc(MAXZIP * sizeof(char));
		char * word = malloc(MAXWORD * sizeof(char));
		int max_words_in_array = 20;
		char ** word_array = malloc(max_words_in_array * sizeof(char *));
		getLine(prompt1, name, MAXNAME);
		if (strcmp(name, "-1") == 0)
		{
			printf("I really hope this demonstrates my ability to use the C language and problemsolve while coding\n");
			free(name);
			break;
		}
		getLine(promptstate, state, MAXSTATE);
		if (strcmp(state, "-1") == 0)
		{
			printf("I really hope this demonstrates my ability to use the C language and problemsolve while coding\n");
			free(name);
			free(state);
			break;
		}
		getLine(promptzip, zip, MAXZIP);
		if (strcmp(zip, "-1") == 0)
		{
			printf("I really hope this demonstrates my ability to use the C language and problemsolve while coding\n");
			free(name);
			free(state);
			free(zip);
			break;
		}
		getLine(promptwords, line, 2000);
		if (strcmp(line, "-1") == 0)
		{
			printf("I really hope this demonstrates my ability to use the C language and problemsolve while coding\n");
			free(name);
			free(state);
			free(zip);
			free(word_array);
			free(line);
			break;
		}
		//take in the words to a string array
		int b = 0;
		int a = 0;
		int num_words = 0;
		while(line[a] != '\0')
		{
			if (line[a] == ' ') //test to see if we've moved to a new cell
			{
				b = 0;
				a++; //to move past the ' '
			}
			word[b] = line[a];
			b++;
			word[b] = '\0';
			//found an entire word, add it to the array
			if (line[a+1] == ' ' || line[a+1] == '\0' || line[a+1] == '\n')
			{
				//ensure the array can handle it
				if (num_words >= max_words_in_array-1)
				{
					max_words_in_array *= 2;
					word_array = realloc(word_array, max_words_in_array * sizeof(char));
				}
				word_array[num_words] = strdup(word);
				num_words++;
			}
			a++;
		}
		if (strlen(name) == 0)
		{
			name = NULL;
		}
		if (strlen(state)==0)
		{
			state = NULL;
		}
		if (strlen(zip) == 0)
		{
			zip = NULL;
		}
		printf("words:\n");
		for (i = 0; i < num_words; ++i)
		{
			printf("%s\n",word_array[i] );
		}
		printf("searched for: name: %s, state: %s, zip: %s, num words: %d\n",name ,state,zip, num_words );
		//using the user entered search, create the business structs
		if (name == NULL && state == NULL && zip == NULL && num_words != 0)
		{
			noNameYesWords(word_array, num_words, reviews_path);
		}
		else
		{
			struct Business ** businesses;
			int t_businesses = 0;
			businesses = get_business_reviews(bst, name, state, zip, word_array, num_words, &t_businesses);

			//print out the businesses
			if (t_businesses != 0)
			{
				for (i = 0; i < t_businesses; ++i)
				{
					printBusiness(businesses[i], i);
				}
			}
			else
			{
				printf("COULD NOT FIND THE BUSINESS\n");
			}
			destroy_business_result(businesses, t_businesses);
		}
		//free the memory
		free(word);
		free(name);
		free(state);
		free(zip);
		for (i = 0; i < num_words; ++i)
		{
			free(word_array[i]);
		}
		free(word_array);
	}

	//free memory
	destroy_business_bst(bst, total_businesses);

	return EXIT_SUCCESS;
}