c-警告:格式"%i"需要类型为"int"的参数,但参数2的类型为"i



我在Linux中使用共享内存创建了一个int的向量(vectorR(,代码如下:

int shmidR, tamR;
tamR = fil*col2;
int *vectorR[tamR]; // Creating the vector
shmidR = shmget(IPC_PRIVATE, sizeof(int)*fil*col2, IPC_CREAT|0666);
vectorR[tamR] = (int*) shmat(shmidR, NULL, 0);

然后我对这个向量进行操作,最后我想打印内容,看看它是否好:

for (int i = 0; i < tamR; i++)
{
printf("%i", vectorR[i]);
}

但我在标题中得到警告:警告:格式"%i"需要类型为"int"的参数,但参数2的类型为"int*"[-Wformat=]

int *vectorR[tamR]创建一个int指针数组。你想要的是一个整数数组。只需使用int vectorR[tamR]

int shmidR, tamR;
tamR = fil*col2;
int vectorR[tamR]; // Creating the vector
shmidR = shmget(IPC_PRIVATE, sizeof(int)*fil*col2, IPC_CREAT|0666);
vectorR[tamR] = (int) shmat(shmidR, NULL, 0);

相关内容

最新更新