Ejemplo n.º 1
0
int main(int argc, char **argv)
{
	long n;
	long N = 2000;
	double pct = 0;
	int last_pct = -1;
	FILE *out;
	
	out = fopen("pi.out", "w");

	fprintf(out, "3.\n");
	for(n = 0; n < 50; n++) {
		fprintf(out, "%d", get_pi_digit(n));
	}
	fprintf(out, "\n");
	
	for(n = 50; n < N; n += 10) {
		pct = (double) n / (double) N;
		if(floor(pct * 100) > last_pct) {
			fprintf(stderr, "\r%d%%", (int) (pct * 100));
			last_pct++;
		}
		print_digits(out, n, 10);
		if(n != 0 && (n + 10) % 50 == 0) {
			fprintf(out, "\n");
		}
	}
	fprintf(stderr, "\r100%%\n");
	fprintf(out, "\n");
	
	fclose(out);
}
/* takes an integer in parameter and prints it */
void print_number(int n)
{
  int min = 0;

  if (n < 0)
    {
      /* take care of INT_MIN scenario */
      if (n == -2147483648)
	{
	  n = -214748364;
	  min = 1;
	}
      n = n * -1;
      print_char('-');
    }

  digits = get_digits(n);
  digitRetainer = digits;
  ten_power = get_power();

  if (n == 0)
    {
      print_char('0');
    }
  else
    {
      print_digits(n);

      if (min == 1) {
	print_char(8 + '0');
      }
    }
}
Ejemplo n.º 3
0
void show_alarm_time(uint8_t hour, uint8_t min, uint8_t sec)
{
	if (get_digits() == 8) {
		dots = 1<<2;
		uint8_t offset = 4;

		data[0] = 'A';
		data[1] = 'l';
		data[2] = 'r';
		data[3] = ' ';
		offset = print_digits(hour, offset);
		offset = print_digits(min, offset);		
	}
	else {
		show_time_setting(hour, min, 0);
	}
}
Ejemplo n.º 4
0
void show_setting_int(char* short_str, char* long_str, int value, bool show_setting)
{
	data[0] = data[1] = data[2] = data[3] = data[4] = data[5] = data[6] = data[7] = ' ';

	if (get_digits() == 8) {
		set_string(long_str);
		print_digits(value, 6);
	}
	else if (get_digits() == 6) {
		set_string(long_str);
		print_digits(value, 4);
	}
	else {
		if (show_setting)
			print_digits(value, 2);
		else
			set_string(short_str);
	}
}
Ejemplo n.º 5
0
// shows time - used when setting time
void show_time_setting(uint8_t hour, uint8_t min, uint8_t sec)
{
	dots = 0;
	uint8_t offset = 0;
	
	switch (digits) {
	case 8:
		offset = print_ch(' ', offset);
		offset = print_ch(' ', offset);
		// fall-through
	case 6:
		offset = print_digits(hour, offset);
		offset = print_ch('-', offset);
		offset = print_digits(min, offset);
		offset = print_ch(' ', offset);
		break;
	case 4:
		offset = print_digits(hour, offset);
		offset = print_digits(min, offset);		
	}
}
void print_number(int n)
{
  int c;

  if (n == 0)
    {
      print_char('0');
      return;
    }
  c = count_digits(n);
  if (n < 0) print_char('-');
  print_digits(n, c);
}
Ejemplo n.º 7
0
void print_arguments(int argc, char *argv[])
{
    int i = 0;

    printf("print letters\n");
    for (i = 0; i < argc; i++) {
        print_letters(argv[i], strlen(argv[i]));
    }

    printf("\n");

    printf("print digits\n");
    for (i = 0; i < argc; i++) {
        print_digits(argv[i], strlen(argv[i]));
    }
}
Ejemplo n.º 8
0
int main() {
	printf("\n\n");
	printf("CS 350 Lab 3 for %s\n\n", "Weicheng Huang Section -01");  

	char value[ARRAYLEN];
	int digits[ARRAYLEN];
	int output;

	printf("Enter an binary number or 'q' to quit(less than 32 chars):");
	scanf("%s", value);
	while (is_q(value)==0) {
		translate(value,digits);
		output = convert(digits);
		print_digits(output,digits);
		printf("Enter an binary number or 'q' to quit(less than 32 chars):");
		scanf("%s", value);
	} 
	printf("Thank you! see ya!\n\n");
}
/* takes an integer in parameter and prints it */
void print_number(int n)
{
  if (n < 0)
    {
      n = n * -1;
      print_char('-');
    }
  
  digits = get_digits(n);
  digitRetainer = digits;
  power = get_power();    

if (n == 0)
    {
      print_char('0');
    }
  else
    {
      print_digits(n);
    }
}
Ejemplo n.º 10
0
void	my_aff_comb()
{
  char	digit1;
  char	digit2;
  char	digit3;

  digit1 = 0;
  while (digit1 <= 7)
    {
      digit2 = digit1 + 1;
      while (digit2 <= 8)
	{
	  digit3 = digit2 + 1;
	  while (digit3 <= 9)
	    {
	      print_digits(digit1, digit2, digit3);
	      digit3 = digit3 + 1;
	    }
	  digit2 = digit2 + 1;
	}
      digit1 = digit1 + 1;
    }
}
Ejemplo n.º 11
0
// shows time based on mode
// 4 digits: hour:min / sec
// 6 digits: hour:min:sec / hour-min
// 8 digits: hour:min:sec / hour-min-sec
void show_time(struct tm* t, bool _24h_clock, uint8_t mode)
{
	dots = 0;

	uint8_t offset = 0;
	uint8_t hour = _24h_clock ? t->hour : t->twelveHour;

	print_dots(mode, t->sec);

	if (mode == 0) { // normal display mode
		if (digits == 8) { // " HH.MM.SS "
			if (!_24h_clock && !t->am)
				offset = print_ch('P', offset);
			else
				offset = print_ch(' ', offset); 
			offset = print_hour(hour, offset, _24h_clock);  // wm
			offset = print_digits(t->min, offset);
			offset = print_digits(t->sec, offset);
			offset = print_ch(' ', offset);
		}
		else if (digits == 6) { // "HH.MM.SS"
			offset = print_hour(hour, offset, _24h_clock);  // wm
			offset = print_digits(t->min, offset);
			offset = print_digits(t->sec, offset);			
		}
		else { // HH.MM
			offset = print_hour(hour, offset, _24h_clock);  // wm
			offset = print_digits(t->min, offset);
		}
	}
	else if (mode == 1) { // extra display mode
		if (digits == 8) { // "HH-MM-SS"
			offset = print_digits(hour, offset);
			offset = print_ch('-', offset);
			offset = print_digits(t->min, offset);
			offset = print_ch('-', offset);
			offset = print_digits(t->sec, offset);
		}
		else if (digits == 6) { // " HH-MM"
			offset = print_digits(hour, offset);
			offset = print_ch('-', offset);
			offset = print_digits(t->min, offset);
			if (!_24h_clock && !t->am)
				offset = print_ch('P', offset);
			else
				offset = print_ch(' ', offset); 
		}
		else { // HH.MM
			if (_24h_clock) {
				offset = print_ch(' ', offset);
				offset = print_digits(t->sec, offset);
				offset = print_ch(' ', offset);
			}
			else {
				if (t->am)
					offset = print_ch('A', offset);
				else
					offset = print_ch('P', offset);

				offset = print_ch('M', offset);
				offset = print_digits(t->sec, offset);
			}
		}
	}
}