Example #1
0
File: storage.c Project: att/uwin
void
init_storage ()
{

  /* Functions: we start with none and ask for more. */
  f_count = 0;
  more_functions ();
  f_names[0] = "(main)";

  /* Variables. */
  v_count = 0;
  more_variables ();
  
  /* Arrays. */
  a_count = 0;
  more_arrays ();

  /* Other things... */
  ex_stack = NULL;
  fn_stack = NULL;
  i_base = 10;
  o_base = 10;
  scale  = 0;
#ifdef READLINE
  n_history = -1;	/* no limit. */
#endif
  c_code = FALSE;
  init_numbers();
}
Example #2
0
int main()
{
	init_numbers(N, nums);
	read_numbers(nums);
	print_numbers(N, nums);
	find_max(N, nums);
	return 0;
}
Example #3
0
int columns_valid() {
  int* numbers = malloc(10 * sizeof(int));
  
  for(int i = 0; i < 9; i++) {
     init_numbers(numbers);
    for(int j = 0; j < 9; j++) {
      numbers[new_places[i + 9 * j] - '0']++;
    }
    for(int k = 1; k < 10; k++) {
      if(numbers[k] != 1) {
	free(numbers);
	return(0);
      }
    }
  }
  free(numbers);
  return(1);
}
Example #4
0
/* Fill an array of int values, prompting the user from stdin;
 * echo the list of numbers entered, then find the max and print it
 */ 
int main()
{ // Prompt the user for the size of the array
  // Store the size in the static integer SIZE
  get_size();
  if(SIZE<=0){
    fprintf(stderr, "Error! The size must be greater than 0!\n");
    exit(-1);
  }
  // Create a new array of numbers, of size "SIZE".
  int numbersArray[SIZE];
  // Pass the pointer to the array into these functions
  // Initialize all elements in the array to -1
  init_numbers(SIZE, numbersArray);
  // Read the user input
  read_numbers(numbersArray);
  // Print all values in the array
  print_numbers(SIZE, numbersArray);
  // Print the max values, evaluated by our functions
  printf("Max number: %d\n", find_max(SIZE, numbersArray));
  printf("Max number out of first half: %d\n", 
      find_max(SIZE/2, numbersArray));
}
Example #5
0
int squares_valid() {
  int* numbers = malloc(10 * sizeof(int));
  int h, i, j, k;
  for(h = 0; h < 3; h++) {
    for(i = 0; i < 3; i++) {
      init_numbers(numbers);
      for(j = 0; j < 3; j++) {
	for(k = 0; k < 3; k++) {
	  numbers[new_places[(h * 9 * 3) + i * 3 + j * 9 + k] - '0']++;
	}
      }
      for(int l = 1; l < 10; l++) {
	if(numbers[l] != 1) {
	  free(numbers);
	  return(0);
	}
      }
    }
  }
  free(numbers);
  return(1);
}
Example #6
0
/* play one numbers round */
void numbers_round(void) {
  int num_large;
  int i, j;
  static int turn = 0;

  /* stages:
      pick numbers
      30 second timer (let Rachel think during this time?)
      reveal answers
      reveal methods
      assign scores
      Rachel's solution */
  printf(" Round %d: Numbers round\n", round);

  printf("It is %s's turn to choose numbers.\n", player[turn].name);

  /* choose numbers */
  init_numbers();
  do {
    printf("%s, how many large numbers? [0 to 4] ", player[turn].name);
    num_large = atoi(get_line());
  } while(num_large < 0 || num_large > 4);

  /* generate numbers */
  for(i = 0; i < num_large; i++) {
    number[i] = get_large();
  }
  for(; i < 6; i++) {
    number[i] = get_small();
  }

  /* display numbers */
  for(j = 6; j >= 0; j--) {
    printf("\r");

    if(nocolour) printf("| ");
    else printf("%s ", letter_colour);

    for(i = 0; i < j; i++) {
      if(number[i] > 9) printf(" ");
      if(number[i] > 99) printf(" ");
      printf("  ");
    }
    for(i = j; i < 6; i++) {
      printf("%d ", number[i]);
    }

    if(nocolour) printf("|");
    else printf("%s", colour_off);
    fflush(stdout);

    usleep(500000);
  }
  putchar('\n');

  speak(RACHEL, "And the target number is...\n");

  /* generate a target */
  for(i = 0; i < 20; i++) {
    printf("  \r");
    if(!nocolour) printf("%s", number_colour);

    printf(" %d ", 100 + (rand() % 900));

    if(!nocolour) printf("%s", colour_off);
    fflush(stdout);

    usleep(100000);
  }
  target = 100 + (rand() % 900);
  printf("  \r");
  if(!nocolour) printf("%s", number_colour);

  printf(" %d ", target);

  if(!nocolour) printf("%s", colour_off);
  printf("\n");

  /* let people think */
  run_timer();

  /* increment the player whose turn it is to choose numbers */
  round++;
  turn++;
  if(turn >= players) turn = 0;
}