Пример #1
0
int main()
{
	clock_t t;
	int f;
	t = clock();
	printf("Calculating...\n");
	f = frequency_of_primes (9999);
	printf("The number of primes lower than 100,000 is : %d\n", f);
	t = clock() - t;
	printf("It took me %d clicks (%f seconds).\n", t, ((float)t)/CLOCKS_PER_SEC);
	return 0;
}
Пример #2
0
int main(void)
{
    
    fprintf(stdout, "clocks_per_sec=%lu\n", CLOCKS_PER_SEC);

	clock_t t;
	int f;
	t = clock();
	printf ("Calculating...\n");
	f = frequency_of_primes (999);
	printf ("The number of primes lower than 100,000 is: %d\n",f);
	
	t = clock() - t;
	printf ("It took me %lu clicks (%f seconds).\n", (long int)t,((float)t)/CLOCKS_PER_SEC);
/*
	t = clock();
	timedWait(3,0);
	t = clock() - t;
	printf("hello: %.2f",((float)t)/CLOCKS_PER_SEC);
*/

/*
	// Nanosleep
	struct timespec timeOut,remains;
	
	timeOut.tv_sec = 4;
	timeOut.tv_nsec = 10000;
	
	t = clock();
	int a;
	for(a=0; a<4; a++){
		fprintf(stdout, "Hello %d\n", a);
		fprintf(stdout, "before: %lu\n", (long int)clock());
		nanosleep(&timeOut, &remains);
		fprintf(stdout, "after: %lu\n", (long int)clock());
	}
	t = clock() - t;
	fprintf(stdout, "For loop took %lu clicks (%f seconds).\n",(long int)t,((float)t)/CLOCKS_PER_SEC);
*/
	
	FILE * test;
	long lSize;
	char * buffer;
	size_t result;
	
	test = fopen("/sys/bus/i2c/devices/0-0054/eeprom", "rb");
	if(test == NULL){
		fprintf(stderr, "Failed to open file\n");
		exit(-1);
	}
	fseek(test, 0, SEEK_END);
	lSize = ftell(test);
	rewind(test);
	fprintf(stdout, "Filesize: %lu\n", lSize);
	
	buffer = (char*) malloc(sizeof(char)*lSize);
	
	//char serial[] = {'C','A','F','E','B','A','B','E'};
	//fwrite(serial, sizeof(char), lSize, test);
	//fwrite(serial, sizeof(char), sizeof(serial), test);
	//rewind(test);
	
	if(buffer == NULL){
		fprintf(stderr, "Memory error\n");
		exit(-1);
	}
	result = fread(buffer, 1, lSize, test);
	/*
	if(result != lSize){
		fprintf(stderr, "something went wrong reading\n");
		exit(-1);
	}
	*/
	
	fprintf(stdout, "%s\n", buffer);
	
	fclose(test);
	
	
	
	return 0;
  
    
}