Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

warning: format ‘%i’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat=]

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=]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading