コード例 #1
0
ファイル: cats.c プロジェクト: grpatter/iu_cs_jegm
// Begin ----------------------------------------------------
void handleInput(char input[101]) {
  if (isnumber(input)) {
    num_arr[index++] = atoi(input);
  }
  else if (strcmp(input, "?") == 0 || strcmp(input, "<") == 0 || strcmp(input, ">") == 0 || strcmp(input, "D") == 0 || strcmp(input, "Save") == 0) {
    oper = input[0];
  }
  else if (strcmp(input, ".") == 0) {
    if (oper == '?') {
      query_relationship(num_arr[0], num_arr[1]);
    } 
    else if (oper == 'D') {
      query_descendants(num_arr[0], num_arr[1]);
      printf("\n");
    }
    else if (oper == '<') {
      add_parent(num_arr[0], num_arr[1]);
    } 
    else if (oper == '>') {
      add_parent(num_arr[1], num_arr[0]);
    }
    else if (oper == 'S') {
      //save_descendants();

      if (catMemory == 0) {
	clearNewToSpace(NUM_CATS, NUM_CATS*2); 
      }
      else {
	clearNewToSpace(0, NUM_CATS); 
      }
    }
    else {
      printf("Invalid Operator. Ignoring.\n");
    }
    index = 0;
  }
  else { 
    if (oper == 'S') {
      parse_saved_cats(input);
    }
    else {
      printf("Invalid input, flushing stdin.\n");
    }
  }
}
コード例 #2
0
ファイル: relationships.c プロジェクト: bcho/homework
int main()
{
    int name_count, relationship_count, query_count;
    int i;

    for (i = 0; i < MAX_PERSON_COUNT; i++)
        PERSON[i][0] = EMPTY_NAME_PREFIX;

    scanf("%d", &name_count);
    read_persons(name_count, PERSON, PERSON_ANCESTOR);

    scanf("%d", &relationship_count);
    union_persons(relationship_count, PERSON, PERSON_ANCESTOR);

    scanf("%d", &query_count);
    query_relationship(query_count, PERSON, PERSON_ANCESTOR);

    return 0;
}