void parse_dihe() { INT ids[4]; DOUBLE temp[3]; STR typea; typea = strtok( NULL, " \t\n" ); if( typea == NULL ) UNERR("Wrong line in " DIHE_TAG " no name"); parse_ints( ids, 4 ); parse_doubles( temp, 2 ); if( strtok( NULL, " \t\n" ) ) UNERR("Wrong line in " DIHE_TAG " too many columns"); if( strcmp( typea, "cosine" ) == 0 ) { parse_doubles( temp+2, 1 ); add_dihe( resolve_pos(ids[0]), resolve_pos(ids[1]), resolve_pos(ids[2]), resolve_pos(ids[3]), temp[0], temp[1], temp[2] ); } else { add_dihe_angle( resolve_pos(ids[0]), resolve_pos(ids[1]), resolve_pos(ids[2]), resolve_pos(ids[3]), temp[1], temp[0] ); } }
void parse_bond() { INT ids[2]; DOUBLE temp[3]; parse_ints( ids, 2 ); parse_doubles( temp, 3 ); if( strtok( NULL, " \t\n" ) ) UNERR("Wrong line in " BOND_TAG " too many columns"); add_bond( resolve_pos(ids[0]), resolve_pos(ids[1]), temp[0], temp[1], temp[2] ); }
int main(int argc, char** argv) { if(argc != 3) { exit(INCORRECT_NUMBER_OF_COMMAND_LINE_ARGUMENTS); } FILE* fp1 = fopen(argv[1], "r+"); FILE* fp2 = fopen(argv[2], "r+"); /*Error check for a null file pointer*/ if(fp1 == NULL || fp2 == NULL) { exit(FILE_FAILED_TO_OPEN); } Vector vec1; Vector vec2; vec1 = parse_ints(fp1); vec2 = parse_ints(fp2); shell_sort(&vec1, vec1.size); shell_sort(&vec2, vec2.size); compare(vec1, vec2, vec1.size, vec2.size); free(vec1.data); free(vec2.data); fclose(fp1); fclose(fp2); if(fp1->_ptr != NULL || fp2->_ptr != NULL) { exit(FILE_FAILED_TO_CLOSE); } return (EXIT_SUCCESS); }
void parse_sub() { STR namei; INT idi; DOUBLE temp[8]; namei = strtok( NULL, " \t\n" ); if( namei == NULL ) UNERR("Wrong line in " SUB_TAG " no name"); parse_ints( &idi, 1 ); parse_doubles( temp, 8 ); if( strtok( NULL, " \t\n" ) ) UNERR("Wrong line in " SUB_TAG " too many columns"); add_sub(namei,idi,temp[0],temp[1],temp[2],temp[3],temp[4],temp[5],temp[6],temp[7]); }
/* * Function: read_array * -------------------- * Читает целые числа в массив * * arr: Массив целых чисел * count: Количество элементов в массиве * * returns: Указатель на массив */ __int64* read_array(__int64* arr, size_t* count) { char* s; while (1) { s = read_string(stdin); if (!strcmp(s, HALT)) { break; } arr = parse_ints(arr, s, count); free(s); } return (__int64*)realloc(arr, sizeof(__int64) * *count); }
/* * Function: read_array * -------------------- * Читает целые числа в массив * * arr: Массив целых чисел * count: Количество элементов в массиве * * returns: Указатель на массив */ int* read_array(int* arr, int* count) { char* s; while (*count < MAX_ELEMENTS) { s = read_string(stdin, 10); if (!strcmp(s, HALT)) { break; } arr = parse_ints(arr, s, count); free(s); } if (*count > MAX_ELEMENTS) { printf(Rus("Вы превысили лимит. Сохраненно только %d элементов\n"), MAX_ELEMENTS); *count = 25; } return (int*)realloc(arr, sizeof(int) * *count); }
command* parse_command() { char buffer[MAX_COMMAND_LEN + 2]; if(fgets(buffer, MAX_COMMAND_LEN + 2, stdin) == null) { command* new_command = (command*) malloc(sizeof(command)); new_command->name[0] = '\0'; return new_command; } if(strlen(buffer) > (size_t) MAX_COMMAND_LEN) { command* new_command = (command*) malloc(sizeof(command)); new_command->name[0] = '\0'; return new_command; } if(strncmp(buffer, "INIT", 4) == 0) { command* new_command = (command*) malloc(sizeof(command)); if(!parse_ints(buffer, 4, 7)) { new_command->name[0] = '\0'; return new_command; } sscanf(buffer, "%s %i %i %i %i %i %i %i", new_command->name, &(new_command->data[0]), &(new_command->data[1]), &(new_command->data[2]), &(new_command->data[3]), &(new_command->data[4]), &(new_command->data[5]), &(new_command->data[6])); new_command->data[3]--; new_command->data[4]--; new_command->data[5]--; new_command->data[6]--; return new_command; } else if(strncmp(buffer, "MOVE", 4) == 0) { command* new_command = (command*) malloc(sizeof(command)); if(!parse_ints(buffer, 4, 4)) { new_command->name[0] = '\0'; return new_command; } sscanf(buffer, "%s %i %i %i %i", new_command->name, &(new_command->data[3]), &(new_command->data[4]), &(new_command->data[5]), &(new_command->data[6])); new_command->data[3]--; new_command->data[4]--; new_command->data[5]--; new_command->data[6]--; return new_command; } else if(strncmp(buffer, "PRODUCE_KNIGHT", 14) == 0) { command* new_command = (command*) malloc(sizeof(command)); if(!parse_ints(buffer, 14, 4)) { new_command->name[0] = '\0'; return new_command; } sscanf(buffer, "%s %i %i %i %i", new_command->name, &(new_command->data[3]), &(new_command->data[4]), &(new_command->data[5]), &(new_command->data[6])); new_command->data[3]--; new_command->data[4]--; new_command->data[5]--; new_command->data[6]--; return new_command; } else if(strncmp(buffer, "PRODUCE_PEASANT", 15) == 0) { command* new_command = (command*) malloc(sizeof(command)); if(!parse_ints(buffer, 15, 4)) { new_command->name[0] = '\0'; return new_command; } sscanf(buffer, "%s %i %i %i %i", new_command->name, &(new_command->data[3]), &(new_command->data[4]), &(new_command->data[5]), &(new_command->data[6])); new_command->data[3]--; new_command->data[4]--; new_command->data[5]--; new_command->data[6]--; return new_command; } else if(strncmp(buffer, "END_TURN", 8) == 0) { command* new_command = (command*) malloc(sizeof(command)); if(strlen(buffer) > strlen("END_TURN\n")) { new_command->name[0] = '\0'; return new_command; } sscanf(buffer, "%s", new_command->name); return new_command; } else { command* new_command = (command*) malloc(sizeof(command)); new_command->name[0] = '\0'; return new_command; } }