Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning while taking input into an int array

Tags:

c

int array[100], i;

for(i = 0; i < 100; i++)
{
  scanf("%d", &array[i]);
}

This is giving me following warning

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

Edit

Actual code:

#include<stdio.h>
#include<stdlib.h>
void main()
{
  int array[100], n, j, ctr = 0, flag = 0;
#define FIX(i) ((array[i]==i)?1:0)
#define CHECK(i,num) ((array[i]==num)&&(array[num]==i)?1:0)
  scanf("%d", n);
  printf("\n");
  for (j = 0; j < n; j++)
  {
    scanf("%d", &array[j]);
    if (array[j] >= n)
    {
      printf("out of range\n");
      return;
    }
    else
    {
      if (FIX(j) == 1)
        ctr++;
      else if ((array[j] < j) && ((CHECK(j,array[j])) == 1) && (flag == 0))
      {
        ctr = ctr + 2;
        flag = 1;
      }
    } //end if
  } //end loop

}
like image 485
Hima Avatar asked Dec 06 '25 20:12

Hima


1 Answers

So based on your actual code:

Fix:

scanf("%d",&n);
           ^ Use ampersand sign

You need to use address of variable

like image 137
P0W Avatar answered Dec 08 '25 11:12

P0W



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!