0
votes

When I compile my project I get the error ("assignment makes integer from pointer without a cast array = NULL"). I don't understand why it works in the if statement and not in the else statement.

    FILE *fp;
int i,j,m,n;
char citemp;

if (!(fp = fopen(trainingsInputFile, "r"))) {
    perror("Datei konnte nicht gelesen werden");
}
else {
    i = 0;
    j = 0;
    n = 0;
    char *carray = (char*)malloc(sizeof(char) * 20);
    while (!feof(fp)) {            
        citemp = getc(fp);

        if(citemp != ';'){                
            if(citemp != ','){ 
                carray[j] = citemp;
                j++;                       
            }else{                    
                trainingsInputArray[n][i] = atof(carray);
                for(m = 0; m < j; m++){
                    carray[m] = NULL;
                }
                j = 0;
                i++;
            }
        }else{
            n++;
            i = 0;
        }
    }
}
fclose(fp);

Error: environment.c:21: warning: assignment makes integer from pointer without a cast [-Wint-conversion] carray[m] = NULL;

1
while(!feof(fp)) is always wrong. - user2736738
Could you please create a minimal, complete and verifiable example? - machine_1
please edit to also include in which line the error appears - kyriakosSt

1 Answers

0
votes

The reason you are getting that error is the line carray[m] = NULL. NULL seems to be defined as ((void*)0), not just 0, so the compiler has correctly recognized that you are assigning a pointer (NULL) to an integer value (carray[m]) which is a char. Change the line to carray[m] = 0 instead and that particular error should go away.