why does it do that

This is a discussion on why does it do that within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> int readValues (FILE *,double *[],double *[],int ); main(int argc, char *argv[]) { FILE *fp; double ...

  1. #1
    Registered User Phoenix_Rebirth's Avatar
    Join Date
    Dec 2005
    Location
    Cyprus
    Posts
    68

    why does it do that

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
     int readValues (FILE *,double *[],double *[],int );
    
    main(int argc, char *argv[])	{
    
        FILE *fp;
        double x[20];
        double y[20];
        int values;
        
        if (argc!=2)	{
        	printf("You haven't input file name");
        	exit(EXIT_FAILURE);
    	}
    	
        printf("Opening file: ",argv[1],"\n");
        fp = fopen(argv[1],"r");
        values = readValues(fp,&x,&y,20);
        fclose(fp);
        system("pause");
    }
    
    int readValues (FILE *fpR,double *xR[20],double *yR[20],int max)	{
    
    }
    I have this code and when i compile it shows
    [Warning] In function `main':

    [Warning] passing arg 2 of `readValues' from incompatible pointer type

    [Warning] passing arg 3 of `readValues' from incompatible pointer type

    Why...

  2. #2
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    You only need to pass the address of the first element:
    Code:
    int readValues (FILE *,double *,double *,int );
    int main(int argc, char *argv[]) 
    {
        double x[20];
        double y[20];
        int foo;
        /* ... */
        /* x and y in value context turn to the address of the first element of the array */
        foo = readValues(fd, x, y, 20); 
        /* ... */
        return 0;
    }
    
    int readValues(FILE *f, double *x, double *y, int max)
    {
        x[5] = 123.456; /* et cetera */
    }

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21