D
D
Denis Yudin2020-06-12 04:07:04
C++ / C#
Denis Yudin, 2020-06-12 04:07:04

How to create an array from an array of words?

For my term paper, I need to create a simple database in C. One point is not clear to me.

Let's say I created a double array of words in C, say 11 football players. Now I want to bind it to a specific team (the topic of work, as it is already clear, is football clubs).
So. How to make an array from this array, so that, for example, on command, c{0}.playera list of these 11 players is displayed to me?

That is, I need to be able to write c{0}.name, c{0}.playerand have the name of the coach + 11 players next to him.
It's all in my data structure linked list. Accordingly, when I enter the next element of the array - so that a new coach name appears + new 11 players, and so on.

As I understand it, this must be done through pointers. But I haven't really figured out exactly how to do this.
Help, please, to understand.
The work must be done in pure C.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom Varlamov, 2020-06-12
@Frontend777

int nrows, ncols;
int i, j;      
double **M;

/* устанавливаем значения nrows и ncols */

/* выделяем память под массив указателей */      
M = (double **)malloc(nrows * sizeof(double *));

/* выделяем память под каждую строчку матрицы */
for(int k = 0; k < nrows; ++k) {
    M[k] = (double *)malloc(ncols * sizeof(double));
}

/* В качестве примера обнуляем значение с индексами i, j */
M[i][j] = 0;

/* Освобождаем память в обратном порядке */
for(int k = 0; k < nrows; ++k) {
    free(M[k]);
}
free(M);

Web source: serg.tk/1/massivy-2d.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question