/**
 * Main entry point for the Triangle classifier.
 */
int main(int argc, char **argv) {

    if ( !valid_input(argc, argv) ) {
        printf("error\n");
        return 0;
    }    
 
    // otherwise all of the supplied arguments were valid. pass the points through
    // to the Triangle classifier.
    long int x1, x2, x3, y1, y2, y3;

    x1 = strtol(argv[1], NULL, 10), y1 = strtol(argv[2], NULL, 10);
    x2 = strtol(argv[3], NULL, 10), y2 = strtol(argv[4], NULL, 10);
    x3 = strtol(argv[5], NULL, 10), y3 = strtol(argv[6], NULL, 10);
    point p1 = {x1, y1};
    point p2 = {x2, y2};
    point p3 = {x3, y3};

    if ( DEBUG ) {
        printf("p1: (%li, %li)\n", p1.x, p1.y);
        printf("p2: (%li, %li)\n", p2.x, p2.y);
        printf("p3: (%li, %li)\n", p3.x, p3.y);
     }

    classify_triangle(&p1, &p2, &p3);
    printf("\n");

    return 0;
}
Exemple #2
0
/*
 * MAIN: Run the program and tests your functions.
 * sample command: ./bignum 4 12 + 13
 * Result: 31
 */
int main(int argc, char** argv) {

	int input_base;

    int* input1;
    int* input2;
    int* result;

	if(argc != 5) { 
		print_usage(argv[0]); 
	}

	input_base = string_to_integer(argv[1]);

	if(!valid_base(input_base)) { 
		fprintf(stderr, "Invalid base: %s\n", argv[1]);
		print_usage(argv[0]);
	}
	

	if(!valid_input(argv[2], input_base)) { 
		fprintf(stderr, "Invalid input1: %s\n", argv[2]);
		print_usage(argv[0]);
	}

	if(!valid_input(argv[4], input_base)) { 
		fprintf(stderr, "Invalid input2: %s\n", argv[4]);
		print_usage(argv[0]);
	}

	if(argv[3][0] != '-' && argv[3][0] != '+') {
		fprintf(stderr, "Invalid operation: %s\n", argv[3]);
		print_usage(argv[0]);
	}

	input1 = string_to_integer_array(argv[2]);
	input2 = string_to_integer_array(argv[4]);

	result = perform_math(input1, input2, argv[3][0], input_base);

	printf("Result: ");
	bignum_print(result);

	printf("\n");
	exit(0);
}
Exemple #3
0
int main(int argc, char *argv[])
{
	if (argc == 1)
		print_usage();

	InputParms input(argv[argc - 1]);

	static struct option options[] = 
	{
		{"outfile", required_argument, 0, 'o'},
		{"outtype", required_argument, 0, 't'},
		{"verbose", no_argument,       0, 'v'},
		{0, 0, 0, 0}
	};

	while (true)
	{
		int index = 0;
		int g = getopt_long(argc, argv, "o:t:v", options, &index);
		if (g == -1)
		{
			if (input.outtype < 1 || input.outtype > 4)
			{
				cout << "Invalid/missing output filetype - Must provide (1=CSV, 2=GPX, 3=TCX, 4=KML)\n";
				exit(EXIT_FAILURE);
			}
			else 
				break;
		}

		switch (g)
		{
			case 0:
				break;
			case 'o':
				input.outfile = string(optarg);
				break;
			case 't':
				input.outtype = atoi(optarg);
				break;
			case 'v':
				input.verbose = true;
				break;
			case '?':
				print_usage();
				break;
			default:
				abort();
		}
	}

	valid_input(input);

	exit(EXIT_SUCCESS);
}