Ejemplo n.º 1
0
int main()
{
    int a[8]={0,0,0,0,1,1,1,1},b[8]={0,0,1,1,0,0,1,1},c[8]={0,1,0,1,0,1,0,1};
    int i;
    int w[8];
    for(i=0;i<8;i++)
    {

        w[i]=add_bin(a[i],b[i]);
    }

    for(i=0;i<8;i++)
    {
        w[i]=mul_bin(w[i],c);
    }

    for(i=0;i<8;i++)
    {
        w[i]=xor_bin(w[i],a);
    }


    printf("The final output is");
    for(i=0;i<8;i++)
    {
        printf("\n%d",w[i]);

    }
}
Ejemplo n.º 2
0
t_bin		*cpy_bin_list(t_bin *from)
{
    t_bin		*ret;

    if (!from || !(from->f))
        return (NULL);
    ret = NULL;
    while (from)
    {
        add_bin(&ret, from->f);
        from = from->next;
    }
    return (ret);
}
int main(int argc, char** argv) {
	// OK, first let's make sure our command line arguments are sane

	if (argc != 5) {
		printf("Usage: %s LUGGAGE_ID FLIGHT_ID DEPARTING ARRIVING\n", argv[0]);
		printf("\tEach argument is a search string for that piece of information\n");
		printf("\tSubstituting a hyphen for a search string acts as a wildcard\n");

		exit(EXIT_FAILURE);
	}

	// OK, our arguments are sane, let's move on and load in all the luggage data

	char buffer[1024];

	memset(&buffer, '\0', 1024);

	bag_carousel *carousel = NULL;

	fflush(stdout);

	while (fgets(buffer, 1024 - 1, stdin) != NULL) {
		if (strlen(buffer) < 2)			// So it will catch new lines
			break;	// Done with stuff

		// Get the bag

		bag_record *bag = read_bag_record(buffer);

		// Store it in the carousel (creating if necessary)

		if (carousel == NULL) {
			// Create the carousel

			carousel = create_carousel(create_bin(bag));
		} else {
			// Make sure we're not replacing something

			bag_bin *bin = find_bin(carousel, bag->luggage_id);

			if (bin == NULL) {
				// Need to add it

				add_bin(carousel, create_bin(bag));
			} else {
				// Need to update it

				update_bin(bin, bag);
			}
		}

		// Reset the buffer, to be safe

		memset(buffer, '\0', 1024);
	}

	// OK, we're done, we'll need to dump bag history, based on our filter

	if (carousel != NULL) {
		print_carousel(carousel, buffer, 1024, argv[1], argv[2], argv[3], argv[4]);

		// Free all the memory we've taken

		cleanup_carousel(carousel);
	}

	exit(EXIT_SUCCESS);
}