本文整理汇总了C++中read_array函数的典型用法代码示例。如果您正苦于以下问题:C++ read_array函数的具体用法?C++ read_array怎么用?C++ read_array使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_array函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fopen
void Vectorizer::load_data(const char* filename)
{
FILE* f = fopen(filename, "rb");
if (f == NULL) error("Could not open %s for reading.", filename);
lock_data();
struct { char magic[4]; int ver; } hdr;
if (fread(&hdr, sizeof(hdr), 1, f) != 1)
error("Error reading %s", filename);
if (hdr.magic[0] != 'H' || hdr.magic[1] != '2' || hdr.magic[2] != 'D' || hdr.magic[3] != 'V')
error("File %s is not a Hermes2D Vectorizer file.", filename);
if (hdr.ver > 1)
error("File %s -- unsupported file version.", filename);
#define read_array(array, type, n, c, what) \
if (fread(&n, sizeof(int), 1, f) != 1) \
error("Error reading the number of " what " from %s", filename); \
lin_init_array(array, type, c, n); \
if (fread(array, sizeof(type), n, f) != n) \
error("Error reading " what " from %s", filename);
read_array(verts, double4, nv, cv, "vertices");
read_array(tris, int3, nt, ct, "triangles");
read_array(edges, int3, ne, ce, "edges");
read_array(dashes, int2, nd, cd, "dashes");
find_min_max();
unlock_data();
fclose(f);
}
示例2: Resize
void Wf_return::read(istream & is){
int nfunc, nst;
string dummy;
is >> dummy >> nfunc;
if(dummy != "nfunc") error("expected nfunc, got ", dummy);
is >> dummy >> nst;
Resize(nfunc, nst);
is >> dummy >> is_complex;
is >> dummy; read_array(is, nfunc, nst, amp);
is >> dummy; read_array(is, nfunc, nst, phase);
is >> dummy; read_array(is, nfunc, nst, cvals);
}
示例3: main
void main()
{
int a[201], n;
clrscr();
// se citeste sirul
n = read_array(a);
// daca a aparut o eroare la citirea datelor se iese din program
if (n == -1)
{
printf("Eroare la citirea datelor!");
getch();
exit(1);
}
// se apeleaza algoritmul de sortare
binary_insertion_sort(a, n);
printf("\ncomparatii: %d\natribuiri: %d\n\nSirul ordonat: ", comp, atr);
// se tipareste sirul sortat
print_array(a, n, 1);
}
示例4: read_value
/* tries to read a symbol's value */
static gboolean
read_value (CtplInputStream *stream,
CtplValue *value,
GError **error)
{
GError *err = NULL;
gchar c;
c = ctpl_input_stream_peek_c (stream, &err);
if (err) {
/* I/O error */
} else if (c == CTPL_STRING_DELIMITER_CHAR) {
read_string (stream, value, &err);
} else if (c == ARRAY_START_CHAR) {
read_array (stream, value, &err);
} else if (c == '.' ||
(c >= '0' && c <= '9') ||
c == '+' || c == '-') {
ctpl_input_stream_read_number (stream, value, &err);
} else {
ctpl_input_stream_set_error (stream, &err, CTPL_ENVIRON_ERROR,
CTPL_ENVIRON_ERROR_LOADER_MISSING_VALUE,
"No valid value can be read");
}
if (err) {
g_propagate_error (error, err);
}
return ! err;
}
示例5: read_whitespace
JsonValue JsonValue::read(const std::string &json, size_t &pos)
{
read_whitespace(json, pos);
if (pos == json.length())
throw JsonException("Unexpected end of JSON data");
switch (json[pos])
{
case '{':
return read_object(json, pos);
case '[':
return read_array(json, pos);
case '"':
return read_string(json, pos);
case '-':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
return read_number(json, pos);
case 'f':
case 't':
return read_boolean(json, pos);
default:
throw JsonException("Unexpected character in JSON data");
}
}
示例6: main
void main()
{
//Сохраняем текущие параметры консоли
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (GetConsoleScreenBufferInfo(hConsole, &csbi))
currentConsoleAttr = csbi.wAttributes;
//Объявляем массив
static int arr[MAX_SIZE][MAX_SIZE];
//Читаем с клавиатуры размер матрицы
size_t n;
printf(Rus("Введите размер матрицы (%d...%d). N: "), MIN_SIZE, MAX_SIZE);
do
{
n = (size_t)read_int(stdin);
if (n < MIN_SIZE || n > MAX_SIZE)
printf(Rus("Неверный размер. Размер должен быть в диапазоне "
"от %d до %d. Повторите ввод: \n"), MIN_SIZE, MAX_SIZE);
} while (n < MIN_SIZE || n > MAX_SIZE);
//Заполняем матрицу
printf(Rus("Вводите элементы массива до заполнения\n"));
UINT8 width = read_array(arr[0], n);
//Выводим матрицу
print_array(arr[0], n, TASK_ZONE, width);
//Считаем значение из задания
UINT64 sum = func_v13(arr[0], n, TASK_ZONE);
printf(Rus("Сумма квадратов отрицательных чисел = %d\n"), sum);
}
示例7: read_deps
static struct list_parse_dep
read_deps (char *s)
{
char *save;
struct list_parse_dep res = {0};
for (char *depstr = strtok_r (s, "#", &save); depstr;
depstr = strtok_r (NULL, "#", &save)) {
char *save2;
char *match, *portstr;
int rule;
rule = atoi (strtok_r (depstr, ";", &save2)) + 1;
match = strtok_r (NULL, ";", &save2);
portstr = strtok_r (NULL, ";", &save2);
uint32_t ports[MAX_ARR_SIZE];
struct arr_ptr_uint32_t nports = read_array (portstr, ports);
struct parse_dep *tmp = xmalloc (sizeof *tmp + nports.n * sizeof *ports);
tmp->rule = rule;
tmp->match = array_from_str (match);
tmp->nports = nports.n;
memcpy (tmp->ports, ports, nports.n * sizeof *ports);
list_append (&res, tmp);
}
return res;
}
示例8: main
int main() {
int size;
scanf("%d", &size);
read_array(size, size);
printf("]\n");
}
示例9: begin_record
BinaryInputStream&
BinaryInputStream::read_record(Numeric::float64* data, int nbr) {
begin_record();
read_array(data, nbr);
end_record();
return *this;
}
示例10: cf_parse_cmd_line
char* cf_parse_cmd_line(int argc, char *argv[]) {
int c;
CONF_ITEM *cf;
option_index = optind = 0;
#ifdef WII
return NULL;
#endif
while ((c = getopt_long(argc, argv, shortopt, longopt, &option_index)) != EOF) {
//if (c != 0) {
// printf("c=%d\n",c);
cf = cf_get_item_by_val(c&0xFFF);
if (cf) {
cf->flags |= CF_SETBYCMD;
// printf("flags %s set on cmd line\n", cf->name);
switch (cf->type) {
case CFT_INT:
CF_VAL(cf) = atoi(optarg);
break;
case CFT_BOOLEAN:
if (c & 0x1000)
CF_BOOL(cf) = 0;
else
CF_BOOL(cf) = 1;
break;
case CFT_STRING:
strcpy(CF_STR(cf), optarg);
//printf("conf %s %s\n",CF_STR(cf),optarg);
break;
case CFT_ARRAY:
read_array(CF_ARRAY(cf), optarg, CF_ARRAY_SIZE(cf));
break;
case CFT_ACTION_ARG:
strcpy(CF_STR(cf), optarg);
if (cf->action) {
exit(cf->action(cf));
}
break;
case CFT_ACTION:
if (cf->action) {
exit(cf->action(cf));
}
break;
case CFT_STR_ARRAY:
/* TODO */
break;
}
//}
}
}
cf_cache_conf();
if (optind >= argc)
return NULL;
return strdup(argv[optind]);
}
示例11: main
int main(){
int i,k,n,arr[50];
printf("Enter the value of n : \t");
scanf("%d",&n);
printf("Enter the array : ");
read_array(arr,n);
insertion_sort(arr,n);
display_array(arr,n);
}
示例12: file_input
void file_input(FILE* file, char* header, char A[MAX_N], char B[MAX_N] ){
char buf[256];
int a, b, num_success;
header[0] = 0;
do{
fgets(buf, MAX_N, file);
strcat(header, buf);
} while(strcmp(buf, "\n"));
//read the numbers
num_success = fscanf(file, "%d %d", &a, &b);
if (num_success < 2)
fail("Failed to read array sizes from input string. Closing...");
fgets(buf, 256, file);
fgets(buf, 256, file); //array a
read_array(buf, A, a, "A");
fgets(buf, 256, file); //array b
read_array(buf, B, b, "B");
};
示例13: main
int main(int argc, const char *argv[])
{
int *v1, *v2, n, cont; //vetor 1, vetor 2, numero de elementos, contador;
puts("Informe o tamanho do vetor:");
scanf("%d", &n);
v1 = (malloc(sizeof(int) * n)); //alocar n endereços de memoria para o vetor 1;
v2 = (malloc(sizeof(int) * n)); //alocar n endereços de memoria para o vetor 2;
printf ( "Lendo o primeiro vetor...\n" );
read_array(n, v1); //vetor 1 recebe os valores;
printf ( "Lendo o segundo vetor...\n" );
read_array(n, v2); //vetor 2 recebe os valores;
printf("O produto escalar é: %d\n", produto_escalar(n, v1, v2)); // printa o retorno da função produto escalar que recebe os dois vetores e o tamanho deles e depois calcula o produto escalar.
return 0;
}
示例14: read_array
//Reads in the command information from the user
//Helps make the program easier to read
int menuType::readCommandInfo(commandType & tempCommand)
{
char * temp = new char [TEMP_SIZE]; //Used to store information from the user
int len = 0; //Used to 'measure' the arrays
//Reads in the infromation from the user and stores it in the passed command
read_array("Command function: ", temp, TEMP_SIZE);
len = strlen(temp);
tempCommand.func = new char[len+1];
strcpy(tempCommand.func, temp);
read_array("Defined rules: ", temp, TEMP_SIZE);
len = strlen(temp);
tempCommand.rules = new char[len+1];
strcpy(tempCommand.rules, temp);
delete [] temp;
}
示例15: fopen
void Orderizer::load_data(const char* filename)
{
FILE* f = fopen(filename, "rb");
if (f == NULL) error("Could not open %s for reading.", filename);
lock_data();
struct { char magic[4]; int ver; } hdr;
if (fread(&hdr, sizeof(hdr), 1, f) != 1)
error("Error reading %s", filename);
if (hdr.magic[0] != 'H' || hdr.magic[1] != '2' || hdr.magic[2] != 'D' || hdr.magic[3] != 'O')
error("File %s is not a Hermes2D Orderizer<Scalar> file.", filename);
if (hdr.ver > 1)
error("File %s -- unsupported file version.", filename);
#define read_array(array, type, n, c, what) \
if (fread(&n, sizeof(int), 1, f) != 1) \
error("Error reading the number of " what " from %s", filename); \
lin_init_array(array, type, c, n); \
if (fread(array, sizeof(type), n, f) != (unsigned) n) \
error("Error reading " what " from %s", filename);
read_array(verts, double3, nv, cv, "vertices");
read_array(tris, int3, nt, ct, "triangles");
read_array(edges, int3, ne, ce, "edges");
read_array(lvert, int, nl, cl1, "label vertices");
lin_init_array(lbox, double2, cl3, nl);
if (fread(lbox, sizeof(double2), nl, f) != (unsigned) nl)
error("Error reading label bounding boxes from %s", filename);
int* orders = new int[nl];
if (fread(orders, sizeof(int), nl, f) != (unsigned) nl)
error("Error reading element orders from %s", filename);
lin_init_array(ltext, char*, cl2, nl);
for (int i = 0; i < nl; i++)
ltext[i] = labels[H2D_GET_H_ORDER(orders[i])][H2D_GET_V_ORDER(orders[i])];
find_min_max();
unlock_data();
fclose(f);
}