Esempio n. 1
0
int main()									// The beginning of our program
{											// This starts the main function
	int list[MAX_NUMBERS]={0}, i=0;			// Initialize the array of integers (numbers) and a counter "i".
											// This line says that we now have storage for MAX_NUMBERS (which is 15) integers.
											// If we didn't have arrays, we would have to do things like:
											// int i, i2, i3, i4, i5, i6, i7, i8, i9, etc... and who wants to do that?? (besides the freak who just raised his hand :) )
	printf("\nThe not so random list:\n\n");

	for(i=0; i < MAX_NUMBERS; i++)			// We call our for loop that will continue to print out MAX_NUMBERS (15) random numbers.
	{										// Start the cycle if the expression in the middle is true.
		list[i] = rand();					// list[i] means, the slot "i" (which will start out as 0) in list gets a random number.
											// Say, the random number came out to be 2200.  In the beginning, since i = 0,  list[0] would equal 2200;
		PRINT_NUM(list[i]);					// If list[i] was 2200, then PRINT_NUM() would print out 2200 to the screen.	
	}										// The end of the cycle, now check at the top to see if we need to continue.
		
											// The for loop will continue to go until i == 15.  Then it will stop.
											// Run this program again and you will notice that the numbers are the same every time.
	printf("\nThe TRULY random list:\n\n");	// They are different from each other, but the same every time.
											// We need to "seed" the random number generator. To do this, we use time.
											// The computers internal clock will always be changing, so we start the random number on our system's time.
	srand( (unsigned int)time(NULL) );		// srand() stands for "seed randomizer"  ... or something like that :)
											// We pass the function time() to srand() to seed the random generator. We pass in NULL to time() because we
											// don't care what format is returned.  However, we need to cast the return value to an unsigned int because
											// that is what srand() wants!

	Sleep(3000);							// This functions causes a delay for about 3 seconds.  1000 is ~ 1 second.  (~ means approximately)

											// Let's see that again...
	for(i=0; i < MAX_NUMBERS; i++)			// Now you'll notice the differences in numbers EVERYTIME ... or at least when the clock changes :)
	{											
		list[i] = rand();					// Randomize the new list
											
		PRINT_NUM(list[i]);					// Print out the randomized number.									
	}
											// Now we will restrict the random numbers so that we don't get numbers in the 10's of thousands.
											// Print the new title of numbers.
	printf("\nThe *restricted* TRULY random list:\n\n");

	Sleep(3000);							// Sleep for 3 seconds

	for(i=0; i < MAX_NUMBERS; i++)			// Now you'll notice the differences in numbers EVERYTIME ... or at least when the clock changes :)
	{											
		list[i] = rand() % 100;				// Randomize the new list with numbers less than 100.
											// using the modulus operator "%" we can restrict the random numbers to being less than 100.
											// Here is another review on how modulus works.  It's kinda like divide.
											// "  15 % 5 = 0,      15 % 7 = 1,    15 % 26 = 15 "
											// Can you see why?  It's the remainder.  15 / 5 = 3 with NO remainder, so 15 % 5 = 0
											// 15 / 7 has a remainder of 1.
											
		PRINT_NUM(list[i]);					// Print out the randomized number.									
	}

	return 0;								// The end of the program 
}											
Esempio n. 2
0
static void
print_statfs(const char *const sample, const char *magic_str)
{
	int fd = open(sample, O_RDONLY);
	if (fd < 0)
		perror_msg_and_fail("open: %s", sample);

	STRUCT_STATFS *const b = tail_alloc(sizeof(*b));
	long rc = SYSCALL_INVOKE(sample, fd, b, sizeof(*b));
	if (rc)
		perror_msg_and_skip(SYSCALL_NAME);

	PRINT_SYSCALL_HEADER(sample, fd, sizeof(*b));
	if (magic_str)
		printf("{f_type=%s", magic_str);
	else
		print_statfs_type("{f_type=", b->f_type);
	PRINT_NUM(f_bsize);
	PRINT_NUM(f_blocks);
	PRINT_NUM(f_bfree);
	PRINT_NUM(f_bavail);
	PRINT_NUM(f_files);
	PRINT_NUM(f_ffree);
#ifdef PRINT_F_FSID
	printf(", f_fsid={%u, %u}",
	       (unsigned) b->PRINT_F_FSID[0], (unsigned) b->PRINT_F_FSID[1]);
#endif
	PRINT_NUM(f_namelen);
#ifdef PRINT_F_FRSIZE
	PRINT_NUM(f_frsize);
#endif
#ifdef PRINT_F_FLAGS
	if (b->f_flags & ST_VALID) {
		printf(", f_flags=");
		printflags(statfs_flags, b->f_flags, "ST_???");
	}
#endif
	printf("}) = 0\n");
}