I have created a vector (vectorR) of ints using shared memory in Linux, the code is as follows:
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);
Then I operate on this vector and at the end i want to print the contents to see if it is good:
for (int i = 0; i < tamR; i++)
{
printf("%i", vectorR[i]);
}
But i get the warning in the Title: warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]
int *vectorR[tamR]
creates a array of int pointers. What you want is an array of integers. Just use 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);