I am having trouble compiling this program, I have just about everything written up but the compiler errors are keeping me stuck at a standstill. In the WRITEARRAY and READARRAY function are where the main compile errors are giving me subscript is not of integral type and this is making no sense to me. Please help with any advice that you could give.

The second error I am seeing is that on line 39 at open=OPENFILEWRITES; i get a cannot convert from float (_cdecl) () to a 'float'

#include <stdio.h>
#define Max 4
#define MAX 6


void main(void)
{
    FILE *openfilewrite ;
    float open, write, read;
    float i, a,b,c,j;
    float arr[Max][MAX], arr1[Max][MAX];
    float INITIALIZE(float ), MULTIPLY(float, int ), OPENFILEWRITES(), OPENFILEREAD(), WRITEARRAY(float), READARRAY();

    printf("Please enter the integer");
    scanf("%f", a);

    arr[Max][MAX]=INITIALIZE(arr[Max][MAX]);

    arr1[Max][MAX]=MULTIPLY(arr[Max][MAX],a);

    open=OPENFILEWRITES;

    write=WRITEARRAY(arr[Max][MAX]);

    read=READARRAY(arr[Max][MAX]);

}




float INITIALIZE(float x)
{
    float i=0, j=0;

    for(i=0; i<4; i++)
    {
        for(j=0; j<6; j++)
        {
            x=(i+j);
        }
    }   
    return(x);
}

float MULTIPLY(float x,int a)
{
    float i=0, j=0;

    for(i=0; i<Max; i++)
    {
        for(j=0; j<MAX; j++)
        {
            x= a*(i+j);
        }
    }
    return(x);
}

float OPENFILEWRITES()
{
    FILE *openfilewrite ;

    if((openfilewrite = fopen("outfile.nums", "w")) == NULL) 
    {                           /*beginning of the if statement*/
    printf("ERROR: file %s can not be opened!\n", "outfile.nums");
    exit();
    }   
}

float WRITEARRAY(float x[Max][MAX])
{
    FILE *openfilewrite ;
    float i=0, j=0;

    for(i=0; i<Max; i++)
    {
        for(j=0; j<MAX; j++)
        {
            fprintf(openfilewrite,"%f", x[i][j]);
        }
    }
}

float OPENFILEREAD()
{
    FILE *openfilewrite ;

    if((openfilewrite = fopen("outfile.nums", "r")) == NULL) 
    {                           /*beginning of the if statement*/
    printf("ERROR: file %s can not be opened!\n", "outfile.nums");
    exit();
    }
}

float READARRAY(float x[Max][MAX])
{
    FILE *openfilewrite ;

    float i=0, j=0;
    for(i=0; i<Max; i++)
    {
        for(j=0; j<MAX; j++)
        {
            fscanf(openfilewrite,"%f", x[i][j]);
        }
    }

}

Correction the errors are at lines 21, 71, 80, and 105

The problem is fairly straightforward, and is exactly what the error message says: in both of the functions, you declare i and j as type float, which is not an integral type - that is to say, it isn't a type which holds only integer values, such as int, short, unsigned int, long, and the like. You cannot use a floating-point number as an index, for reasons that should be tolerably clear (i.e., you can't have a fractional index to an array). If you simply change the declarations to type int, the problem should resolve itself.

The error on line 21 is that you forgot the () to call the function. So you're trying to assign a function to a double variable.

The error on line 105 is that the argument to scanf needs to be a pointer, not a double. Also you're using openfilewrite uninitialized, so it's UB.

PS: The last three of your functions don't contain a return statement even though they're declared to have a non-void return value.

ok thank you that did fix that problem. Sometimes it takes another set of eyes to see the obvious. What about the second issue i had with the conversion of a float(_cdecl)() to a 'float', if you could help explain what the problem with that is i would be grateful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.