...

问题描述 投票:1回答:1
I found a solution.

I have to change the number of row (5) with the number of columns (9) when I create the array of pointer.

#define MATRIX 1518

int (*matrix)[5], shmMatrix;
shmMatrix = shmget(MATRIX, sizeof(int[5][9]), IPC_CREAT | IPC_EXCL | 0770);
matrix = shmat(shmMatrix, NULL, 0);

for (int i = 1; i <= 8; i++) matrix[0][i] = -5;

我有一个问题,在C语言的共享内存中使用矩阵。

|       0       -5      -5      -5      -5      -5      -5      -5      -5      |
|       -5      -5      -5      -5      0       0       0       0       0       |
|       0       0       0       0       0       0       0       0       0       |
|       0       0       0       0       0       0       0       0       0       |
|       0       0       0       0       0       0       0       0       0       |

我已经在这里合成了代码。但如果我在shm中打印矩阵,就会出现这种情况:

在shm中创建矩阵时,我使用了:
c matrix shared-memory
1个回答
0
投票

我有一个在C语言中使用共享内存中的矩阵的问题,我在这里合成了代码。#define MATRIX 1518 int (*matrix)[5], shmMatrix; shmMatrix = shmget(MATRIX, sizeof(int[5][9]), IPC_CREAT。

© www.soinside.com 2019 - 2024. All rights reserved.