How to clear these warnings?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmaltech28
    New Member
    • Nov 2009
    • 2

    How to clear these warnings?

    Iv written a C program for playing tic-tac-toe between a computer and a user. Iv used lots of pointer variables and passing those variables to functions to functions. Im getting some warnings and also the program is not executing properly. I dont know whether it is because of warnings or I did logical errors in the program.
    WARNING:
    1. assignment makes a pointer from Integer without a cast.
    2. passing arg1 of 'display' from incompatible pointer type.
    Could anybody help me to give solution to this warning. It will be better if you guide why im not getting the expected output.
    Below I place the error code. If u have to see my whole program for better checking it go to http://paste.pocoo.org/show/250129/
    Compiled in gcc..

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    void display();
    int main()
    {
    int *a[3][3],i,j;
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    a[i][j]=0;
    }
    a[1][1]=1;      //this is where I get the first warning
    display(&a);    //and the second warning is this
    return 0;
    }
    void display(int *p)
    {
    int *a[3][3],i,j;
    for(i=0;i<3;i++)
    {
    for(j=0;j<3;j++)
    {
    a[i][j]=*p;
    p++;
    printf("%d\t",a[i][j]);
    }
    printf("\n");
    }
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Code:
    a[1][1]=1;      //this is where I get the first warning
    The array is a 3x3 array of pointers to int. Therefore, you need to assign addresses of int rather than int values. That is, 1 is not a valid address for an int.

    Did you mean you have a exe array of int?

    Code:
    display(&a);    //and the second warning is this
    Your display function takes an int* argument but your prototype says no arguments.

    Comment

    Working...